From b0f8350f9fde244b96c11526e670fe46dd15e416 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 30 Jul 2024 21:12:36 +0200 Subject: [PATCH 1/6] test: Correct misconfigured mocks --- tests/Uri/UriRetrieverTest.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 24714a26..a6193723 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -235,24 +235,26 @@ public function testResolveExcessLevelUp() public function testConfirmMediaTypeAcceptsJsonSchemaType() { - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface', array('getContentType')); + $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', array('getContentType')); + $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)); } /** @@ -260,13 +262,14 @@ public function testConfirmMediaTypeAcceptsJsonType() */ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() { - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface', array('getContentType')); + $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) @@ -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', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -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', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -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', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); $retriever->addInvalidContentTypeEndpoint('http://example.com'); From a84d6d2f3152f35d952ebbf0b4f42b97fdfb2781 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 30 Jul 2024 21:13:22 +0200 Subject: [PATCH 2/6] test: Refactor to use willReturn() method --- tests/Uri/UriRetrieverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index a6193723..3d124b45 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -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; } From 9a503acc548f5f1937a93cd814aef273635f37a5 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 30 Jul 2024 21:13:59 +0200 Subject: [PATCH 3/6] test: Make use of already imported classname --- tests/Uri/UriRetrieverTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 3d124b45..decec519 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -153,7 +153,7 @@ public function testResolvePointerNoFragment() 'title' => 'schema' ); - $retriever = new \JsonSchema\Uri\UriRetriever(); + $retriever = new UriRetriever(); $this->assertEquals( $schema, $retriever->resolvePointer( @@ -173,7 +173,7 @@ public function testResolvePointerFragment() 'title' => 'schema' ); - $retriever = new \JsonSchema\Uri\UriRetriever(); + $retriever = new UriRetriever(); $this->assertEquals( $schema->definitions->foo, $retriever->resolvePointer( @@ -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' ); @@ -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' ); @@ -227,7 +227,7 @@ public function testResolvePointerFragmentNoArray() */ public function testResolveExcessLevelUp() { - $retriever = new \JsonSchema\Uri\UriRetriever(); + $retriever = new UriRetriever(); $retriever->resolve( '../schema.json#', 'http://example.org/schema.json#' ); From ce23a0f7a8b594a24cc6f782082ea3966ba41124 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 30 Jul 2024 21:14:25 +0200 Subject: [PATCH 4/6] test: Ignore return value when exception is expected to be thrown --- tests/Uri/UriRetrieverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index decec519..daf764c1 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -392,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() From 6586a98fa737dafd1a94a734b8cac010f1a7af56 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 30 Jul 2024 21:20:48 +0200 Subject: [PATCH 5/6] test: Mock complete interface --- tests/Uri/UriRetrieverTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index daf764c1..3c500699 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -235,7 +235,7 @@ public function testResolveExcessLevelUp() public function testConfirmMediaTypeAcceptsJsonSchemaType() { - $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface', array('getContentType')); + $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $retriever = new UriRetriever(); $uriRetriever->expects($this->at(0)) @@ -247,7 +247,7 @@ public function testConfirmMediaTypeAcceptsJsonSchemaType() public function testConfirmMediaTypeAcceptsJsonType() { - $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface', array('getContentType')); + $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $retriever = new UriRetriever(); $uriRetriever->expects($this->at(0)) @@ -262,7 +262,7 @@ public function testConfirmMediaTypeAcceptsJsonType() */ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() { - $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface', array('getContentType')); + $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $retriever = new UriRetriever(); $uriRetriever->expects($this->at(0)) @@ -335,7 +335,7 @@ public function testRetrieveSchemaFromPackage() public function testInvalidContentTypeEndpointsDefault() { - $mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface', array('getContentType')); + $mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -348,7 +348,7 @@ public function testInvalidContentTypeEndpointsDefault() */ public function testInvalidContentTypeEndpointsUnknown() { - $mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface', array('getContentType')); + $mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -357,7 +357,7 @@ public function testInvalidContentTypeEndpointsUnknown() public function testInvalidContentTypeEndpointsAdded() { - $mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface', 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'); From 561e806f7b5ac698e827f9020a0ebde4cf9f7825 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 30 Jul 2024 21:23:10 +0200 Subject: [PATCH 6/6] docs: Add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b58dc66e..fc3114ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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