Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Correct misconfigured mocks in JsonSchema\Tests\Uri\UriRetrieverTest ([#741](https://github.com/jsonrainbow/json-schema/pull/741))

## [6.0.0] - 2024-07-30
### Added
Expand Down
47 changes: 25 additions & 22 deletions tests/Uri/UriRetrieverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private function getRetrieverMock($returnSchema)
$retriever->expects($this->at(0))
->method('retrieve')
->with($this->equalTo(null), $this->equalTo('http://some.host.at/somewhere/parent'))
->will($this->returnValue($jsonSchema));
->willReturn($jsonSchema);

return $retriever;
}
Expand Down Expand Up @@ -153,7 +153,7 @@ public function testResolvePointerNoFragment()
'title' => 'schema'
);

$retriever = new \JsonSchema\Uri\UriRetriever();
$retriever = new UriRetriever();
$this->assertEquals(
$schema,
$retriever->resolvePointer(
Expand All @@ -173,7 +173,7 @@ public function testResolvePointerFragment()
'title' => 'schema'
);

$retriever = new \JsonSchema\Uri\UriRetriever();
$retriever = new UriRetriever();
$this->assertEquals(
$schema->definitions->foo,
$retriever->resolvePointer(
Expand All @@ -196,7 +196,7 @@ public function testResolvePointerFragmentNotFound()
'title' => 'schema'
);

$retriever = new \JsonSchema\Uri\UriRetriever();
$retriever = new UriRetriever();
$retriever->resolvePointer(
$schema, 'http://example.org/schema.json#/definitions/bar'
);
Expand All @@ -216,7 +216,7 @@ public function testResolvePointerFragmentNoArray()
'title' => 'schema'
);

$retriever = new \JsonSchema\Uri\UriRetriever();
$retriever = new UriRetriever();
$retriever->resolvePointer(
$schema, 'http://example.org/schema.json#/definitions/foo'
);
Expand All @@ -227,46 +227,49 @@ public function testResolvePointerFragmentNoArray()
*/
public function testResolveExcessLevelUp()
{
$retriever = new \JsonSchema\Uri\UriRetriever();
$retriever = new UriRetriever();
$retriever->resolve(
'../schema.json#', 'http://example.org/schema.json#'
);
}

public function testConfirmMediaTypeAcceptsJsonSchemaType()
{
$retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
$uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
$retriever = new UriRetriever();

$retriever->expects($this->at(0))
$uriRetriever->expects($this->at(0))
->method('getContentType')
->will($this->returnValue('application/schema+json'));
->willReturn('application/schema+json');

$this->assertEquals(null, $retriever->confirmMediaType($retriever, null));
$this->assertEquals(null, $retriever->confirmMediaType($uriRetriever, null));
}

public function testConfirmMediaTypeAcceptsJsonType()
{
$retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
$uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
$retriever = new UriRetriever();

$retriever->expects($this->at(0))
$uriRetriever->expects($this->at(0))
->method('getContentType')
->will($this->returnValue('application/json'));
->willReturn('application/json');

$this->assertEquals(null, $retriever->confirmMediaType($retriever, null));
$this->assertEquals(null, $retriever->confirmMediaType($uriRetriever, null));
}

/**
* @expectedException \JsonSchema\Exception\InvalidSchemaMediaTypeException
*/
public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes()
{
$retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
$uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
$retriever = new UriRetriever();

$retriever->expects($this->at(0))
$uriRetriever->expects($this->at(0))
->method('getContentType')
->will($this->returnValue('text/html'));
->willReturn('text/html');

$this->assertEquals(null, $retriever->confirmMediaType($retriever, null));
$this->assertEquals(null, $retriever->confirmMediaType($uriRetriever, null));
}

private function mockRetriever($schema)
Expand Down Expand Up @@ -332,7 +335,7 @@ public function testRetrieveSchemaFromPackage()

public function testInvalidContentTypeEndpointsDefault()
{
$mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
$mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
$mock->method('getContentType')->willReturn('Application/X-Fake-Type');
$retriever = new UriRetriever();

Expand All @@ -345,7 +348,7 @@ public function testInvalidContentTypeEndpointsDefault()
*/
public function testInvalidContentTypeEndpointsUnknown()
{
$mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
$mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
$mock->method('getContentType')->willReturn('Application/X-Fake-Type');
$retriever = new UriRetriever();

Expand All @@ -354,7 +357,7 @@ public function testInvalidContentTypeEndpointsUnknown()

public function testInvalidContentTypeEndpointsAdded()
{
$mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
$mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
$mock->method('getContentType')->willReturn('Application/X-Fake-Type');
$retriever = new UriRetriever();
$retriever->addInvalidContentTypeEndpoint('http://example.com');
Expand Down Expand Up @@ -389,7 +392,7 @@ public function testLoadSchemaJSONDecodingException()
'JsonSchema\Exception\JsonDecodingException',
'JSON syntax is malformed'
);
$schema = $retriever->retrieve('package://tests/fixtures/bad-syntax.json');
$retriever->retrieve('package://tests/fixtures/bad-syntax.json');
}

public function testGenerateURI()
Expand Down