From b41bb84effcc38665e5b25cc4498d0c21f9fabd3 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 30 Jul 2024 19:54:49 +0200 Subject: [PATCH 01/19] ci: Add PHP 8.0 and greater to build matrix --- .github/workflows/continuous-integration.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a72829ed..801c2f7a 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -26,7 +26,10 @@ jobs: - "7.2" - "7.3" - "7.4" -# - "8.0" + - "8.0" + - "8.1" + - "8.2" + - "8.3" dependencies: [highest] experimental: [false] include: From 2d265b8434c64fbc82c640becd1734de1df13aea Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 30 Jul 2024 20:31:10 +0200 Subject: [PATCH 02/19] ci: Remove PHP 5.3 - 7.1 from workflows --- .github/workflows/continuous-integration.yml | 10 ++-------- .github/workflows/lint.yml | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 801c2f7a..e45c7726 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -17,12 +17,6 @@ jobs: strategy: matrix: php-version: - - "5.3" - - "5.4" - - "5.5" - - "5.6" - - "7.0" - - "7.1" - "7.2" - "7.3" - "7.4" @@ -33,10 +27,10 @@ jobs: dependencies: [highest] experimental: [false] include: - - php-version: "5.3" + - php-version: "7.2" dependencies: highest experimental: false - - php-version: "5.3" + - php-version: "7.2" dependencies: lowest experimental: false # - php-version: "8.0" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d61f8c46..e16034f2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: php-version: - - "5.3" + - "7.2" - "latest" steps: From 1aeadd7ba20ff9475c5b350d0ec530381955f8bf Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 30 Jul 2024 20:32:40 +0200 Subject: [PATCH 03/19] build: Require minimum PHP 7.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 827cff0d..15442d78 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ } ], "require": { - "php": ">=5.3.3", + "php": "^7.2 || ^8.0", "marc-mabe/php-enum":"^2.0 || ^3.0 || ^4.0", "icecave/parity": "1.0.0" }, From 58b2b762c292fff4fd25feccfac87e7ed0768f95 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 30 Jul 2024 21:30:29 +0200 Subject: [PATCH 04/19] build: Upgrade to PHPUnit 8.5 --- composer.json | 2 +- phpunit.xml.dist | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 15442d78..247fb9db 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "~2.2.20 || ~2.19.0", "json-schema/json-schema-test-suite": "1.2.0", - "phpunit/phpunit": "^4.8.35" + "phpunit/phpunit": "^8.5" }, "extra": { "branch-alias": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0136d8ed..f49455f2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,8 @@ - From 2a431f2147599414e20a6dd2858c6a51c78142b2 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 30 Jul 2024 21:31:16 +0200 Subject: [PATCH 05/19] refactor: Add now required void return types for setup() methods --- tests/Constraints/CoerciveTest.php | 2 +- tests/Constraints/FactoryTest.php | 2 +- tests/Constraints/FormatTest.php | 2 +- tests/Constraints/MinLengthMaxLengthMultiByteTest.php | 2 +- tests/Iterators/ObjectIteratorTest.php | 2 +- tests/Uri/Retrievers/PredefinedArrayTest.php | 2 +- tests/Uri/UriResolverTest.php | 2 +- tests/Uri/UriRetrieverTest.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Constraints/CoerciveTest.php b/tests/Constraints/CoerciveTest.php index 22684b3e..3c08d384 100644 --- a/tests/Constraints/CoerciveTest.php +++ b/tests/Constraints/CoerciveTest.php @@ -18,7 +18,7 @@ class CoerciveTest extends VeryBaseTestCase { protected $factory = null; - public function setUp() + public function setUp(): void { $this->factory = new Factory(); $this->factory->setConfig(Constraint::CHECK_MODE_TYPE_CAST | Constraint::CHECK_MODE_COERCE_TYPES); diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index adc11844..e7f96ad4 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -42,7 +42,7 @@ class FactoryTest extends TestCase */ protected $factory; - protected function setUp() + protected function setUp(): void { $this->factory = new Factory(); } diff --git a/tests/Constraints/FormatTest.php b/tests/Constraints/FormatTest.php index 78706c33..c49b5c68 100644 --- a/tests/Constraints/FormatTest.php +++ b/tests/Constraints/FormatTest.php @@ -17,7 +17,7 @@ class FormatTest extends BaseTestCase { protected $validateSchema = true; - public function setUp() + public function setUp(): void { date_default_timezone_set('UTC'); } diff --git a/tests/Constraints/MinLengthMaxLengthMultiByteTest.php b/tests/Constraints/MinLengthMaxLengthMultiByteTest.php index b19ec4f7..3e7d91e2 100644 --- a/tests/Constraints/MinLengthMaxLengthMultiByteTest.php +++ b/tests/Constraints/MinLengthMaxLengthMultiByteTest.php @@ -13,7 +13,7 @@ class MinLengthMaxLengthMultiByteTest extends BaseTestCase { protected $validateSchema = true; - protected function setUp() + protected function setUp(): void { if (!extension_loaded('mbstring')) { $this->markTestSkipped('mbstring extension is not available'); diff --git a/tests/Iterators/ObjectIteratorTest.php b/tests/Iterators/ObjectIteratorTest.php index e36d2ea4..a226c060 100644 --- a/tests/Iterators/ObjectIteratorTest.php +++ b/tests/Iterators/ObjectIteratorTest.php @@ -16,7 +16,7 @@ class ObjectIteratorTest extends TestCase { protected $testObject; - public function setUp() + public function setUp(): void { $this->testObject = (object) array( 'subOne' => (object) array( diff --git a/tests/Uri/Retrievers/PredefinedArrayTest.php b/tests/Uri/Retrievers/PredefinedArrayTest.php index 7684bb1f..7ba0106d 100644 --- a/tests/Uri/Retrievers/PredefinedArrayTest.php +++ b/tests/Uri/Retrievers/PredefinedArrayTest.php @@ -12,7 +12,7 @@ class PredefinedArrayTest extends TestCase { private $retriever; - public function setUp() + public function setUp(): void { $this->retriever = new PredefinedArray( array( diff --git a/tests/Uri/UriResolverTest.php b/tests/Uri/UriResolverTest.php index b0207cb7..12624d90 100644 --- a/tests/Uri/UriResolverTest.php +++ b/tests/Uri/UriResolverTest.php @@ -9,7 +9,7 @@ class UriResolverTest extends TestCase { private $resolver; - public function setUp() + public function setUp(): void { $this->resolver = new UriResolver(); } diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 3c500699..8f9608bd 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -21,7 +21,7 @@ class UriRetrieverTest extends TestCase { protected $validator; - protected function setUp() + protected function setUp(): void { $this->validator = new Validator(); } From 1c4f5178e6fa03b8b78daae732607f3af4496b9d Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 14:35:58 +0200 Subject: [PATCH 06/19] build: Include phpspec/prophecy dependency --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 247fb9db..1e79a522 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,8 @@ "require-dev": { "friendsofphp/php-cs-fixer": "~2.2.20 || ~2.19.0", "json-schema/json-schema-test-suite": "1.2.0", - "phpunit/phpunit": "^8.5" + "phpunit/phpunit": "^8.5", + "phpspec/prophecy": "^1.19" }, "extra": { "branch-alias": { From e6eac1827f6b44a9c72679f3c3bb34aaf4b681eb Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 14:38:24 +0200 Subject: [PATCH 07/19] refactor: Replace setExpectedException with expectException/expectExceptionMessage --- tests/ConstraintErrorTest.php | 7 +++---- tests/Constraints/FactoryTest.php | 2 +- tests/Constraints/SchemaValidationTest.php | 13 +++++-------- tests/Constraints/SelfDefinedSchemaTest.php | 2 +- tests/Constraints/TypeTest.php | 14 ++++++-------- tests/Constraints/ValidationExceptionTest.php | 2 +- tests/Entity/JsonPointerTest.php | 7 +++---- tests/RefTest.php | 2 +- tests/SchemaStorageTest.php | 12 ++++-------- tests/Uri/Retrievers/CurlTest.php | 7 +++---- tests/Uri/UriRetrieverTest.php | 7 +++---- tests/ValidatorTest.php | 2 +- 12 files changed, 32 insertions(+), 45 deletions(-) diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index bd0082f0..487f7d2a 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -24,10 +24,9 @@ public function testGetInvalidMessage() { $e = ConstraintError::MISSING_ERROR(); - $this->setExpectedException( - '\JsonSchema\Exception\InvalidArgumentException', - 'Missing error message for missingError' - ); + $this->expectException('\JsonSchema\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Missing error message for missingError'); + $e->getMessage(); } } diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index e7f96ad4..d3591354 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -85,7 +85,7 @@ public function constraintNameProvider() */ public function testExceptionWhenCreateInstanceForInvalidConstraintName($constraintName) { - $this->setExpectedException('JsonSchema\Exception\InvalidArgumentException'); + $this->expectException('JsonSchema\Exception\InvalidArgumentException'); $this->factory->createInstanceFor($constraintName); } diff --git a/tests/Constraints/SchemaValidationTest.php b/tests/Constraints/SchemaValidationTest.php index 85907c5d..08bc42cb 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -102,19 +102,16 @@ public function testValidCases($schema) public function testNonObjectSchema() { - $this->setExpectedException( - '\JsonSchema\Exception\RuntimeException', - 'Cannot validate the schema of a non-object' - ); + $this->expectException('\JsonSchema\Exception\RuntimeException'); + $this->expectExceptionMessage('Cannot validate the schema of a non-object'); + $this->testValidCases('"notAnObject"'); } public function testInvalidSchemaException() { - $this->setExpectedException( - '\JsonSchema\Exception\InvalidSchemaException', - 'Schema did not pass validation' - ); + $this->expectException('\JsonSchema\Exception\InvalidSchemaException'); + $this->expectExceptionMessage('Schema did not pass validation'); $input = json_decode('{}'); $schema = json_decode('{"properties":{"propertyOne":{"type":"string","required":true}}}'); diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index 70108eb6..2dc4871b 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -74,7 +74,7 @@ public function testInvalidArgumentException() $v = new Validator(); - $this->setExpectedException('\JsonSchema\Exception\InvalidArgumentException'); + $this->expectException('\JsonSchema\Exception\InvalidArgumentException'); $v->validate($value, $schema); } diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index a10996da..1c281f0b 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -125,10 +125,9 @@ public function testInvalidateTypeNameWording() $m = $r->getMethod('validateTypeNameWording'); $m->setAccessible(true); - $this->setExpectedException( - '\UnexpectedValueException', - "No wording for 'notAValidTypeName' available, expected wordings are: [an integer, a number, a boolean, an object, an array, a string, a null]" - ); + $this->expectException('\UnexpectedValueException'); + $this->expectExceptionMessage("No wording for 'notAValidTypeName' available, expected wordings are: [an integer, a number, a boolean, an object, an array, a string, a null]"); + $m->invoke($t, 'notAValidTypeName'); } @@ -138,10 +137,9 @@ public function testValidateTypeException() $data = new \stdClass(); $schema = json_decode('{"type": "notAValidTypeName"}'); - $this->setExpectedException( - 'JsonSchema\Exception\InvalidArgumentException', - 'object is an invalid type for notAValidTypeName' - ); + $this->expectException('JsonSchema\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('object is an invalid type for notAValidTypeName'); + $t->check($data, $schema); } } diff --git a/tests/Constraints/ValidationExceptionTest.php b/tests/Constraints/ValidationExceptionTest.php index 57995769..317fc13f 100644 --- a/tests/Constraints/ValidationExceptionTest.php +++ b/tests/Constraints/ValidationExceptionTest.php @@ -45,7 +45,7 @@ public function testValidationException() $exception->getMessage() ); - $this->setExpectedException('JsonSchema\Exception\ValidationException'); + $this->expectException('JsonSchema\Exception\ValidationException'); throw $exception; } } diff --git a/tests/Entity/JsonPointerTest.php b/tests/Entity/JsonPointerTest.php index d063d32d..70feb172 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -113,10 +113,9 @@ public function testJsonPointerWithPropertyPaths() public function testCreateWithInvalidValue() { - $this->setExpectedException( - '\JsonSchema\Exception\InvalidArgumentException', - 'Ref value must be a string' - ); + $this->expectException('\JsonSchema\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Ref value must be a string'); + new JsonPointer(null); } } diff --git a/tests/RefTest.php b/tests/RefTest.php index 64525122..a356a413 100644 --- a/tests/RefTest.php +++ b/tests/RefTest.php @@ -69,7 +69,7 @@ public function testRefIgnoresSiblings($schema, $document, $isValid, $exception $v = new Validator(); if ($exception) { - $this->setExpectedException($exception); + $this->expectException($exception); } $v->validate($document, $schema); diff --git a/tests/SchemaStorageTest.php b/tests/SchemaStorageTest.php index ebbc9477..d4e812cb 100644 --- a/tests/SchemaStorageTest.php +++ b/tests/SchemaStorageTest.php @@ -102,10 +102,8 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference() public function testUnresolvableJsonPointExceptionShouldBeThrown() { - $this->setExpectedException( - 'JsonSchema\Exception\UnresolvableJsonPointerException', - 'File: http://www.example.com/schema.json is found, but could not resolve fragment: #/definitions/car' - ); + $this->expectException('JsonSchema\Exception\UnresolvableJsonPointerException'); + $this->expectExceptionMessage('File: http://www.example.com/schema.json is found, but could not resolve fragment: #/definitions/car'); $mainSchema = $this->getInvalidSchema(); $mainSchemaPath = 'http://www.example.com/schema.json'; @@ -121,10 +119,8 @@ public function testUnresolvableJsonPointExceptionShouldBeThrown() public function testResolveRefWithNoAssociatedFileName() { - $this->setExpectedException( - 'JsonSchema\Exception\UnresolvableJsonPointerException', - "Could not resolve fragment '#': no file is defined" - ); + $this->expectException('JsonSchema\Exception\UnresolvableJsonPointerException'); + $this->expectExceptionMessage("Could not resolve fragment '#': no file is defined"); $schemaStorage = new SchemaStorage(); $schemaStorage->resolveRef('#'); diff --git a/tests/Uri/Retrievers/CurlTest.php b/tests/Uri/Retrievers/CurlTest.php index 550baff1..431606b9 100644 --- a/tests/Uri/Retrievers/CurlTest.php +++ b/tests/Uri/Retrievers/CurlTest.php @@ -17,10 +17,9 @@ public function testRetrieveNonexistantFile() { $c = new Curl(); - $this->setExpectedException( - '\JsonSchema\Exception\ResourceNotFoundException', - 'JSON schema not found' - ); + $this->expectException('\JsonSchema\Exception\ResourceNotFoundException'); + $this->expectExceptionMessage('JSON schema not found'); + $c->retrieve(__DIR__ . '/notARealFile'); } diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 8f9608bd..3b76dfdc 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -388,10 +388,9 @@ public function testLoadSchemaJSONDecodingException() { $retriever = new UriRetriever(); - $this->setExpectedException( - 'JsonSchema\Exception\JsonDecodingException', - 'JSON syntax is malformed' - ); + $this->expectException('JsonSchema\Exception\JsonDecodingException'); + $this->expectExceptionMessage('JSON syntax is malformed'); + $retriever->retrieve('package://tests/fixtures/bad-syntax.json'); } diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index ca62e45c..774d2c11 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -31,7 +31,7 @@ public function testBadAssocSchemaInput() $validator = new Validator(); - $this->setExpectedException('\JsonSchema\Exception\InvalidArgumentException'); + $this->expectException('\JsonSchema\Exception\InvalidArgumentException'); $validator->validate($data, $schema); } From eb413260c27e8d748b4c80d4df02b125c48b1be4 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 14:42:09 +0200 Subject: [PATCH 08/19] refactor: Replace @expectedException annotation for expectException method --- tests/Constraints/FactoryTest.php | 10 +++----- tests/Uri/Retrievers/FileGetContentsTest.php | 6 ++--- tests/Uri/Retrievers/PredefinedArrayTest.php | 4 +-- tests/Uri/UriResolverTest.php | 13 +++------- tests/Uri/UriRetrieverTest.php | 26 ++++++++------------ 5 files changed, 21 insertions(+), 38 deletions(-) diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index d3591354..ac573d3f 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -96,19 +96,17 @@ public function invalidConstraintNameProvider() ); } - /** - * @expectedException \JsonSchema\Exception\InvalidArgumentException - */ public function testSetConstraintClassExistsCondition() { + $this->expectException(\JsonSchema\Exception\InvalidArgumentException::class); + $this->factory->setConstraintClass('string', 'SomeConstraint'); } - /** - * @expectedException \JsonSchema\Exception\InvalidArgumentException - */ public function testSetConstraintClassImplementsCondition() { + $this->expectException(\JsonSchema\Exception\InvalidArgumentException::class); + $this->factory->setConstraintClass('string', 'JsonSchema\Tests\Constraints\MyBadConstraint'); } diff --git a/tests/Uri/Retrievers/FileGetContentsTest.php b/tests/Uri/Retrievers/FileGetContentsTest.php index 2301f3bc..6f8f2b3f 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -10,12 +10,12 @@ */ class FileGetContentsTest extends TestCase { - /** - * @expectedException \JsonSchema\Exception\ResourceNotFoundException - */ public function testFetchMissingFile() { $res = new FileGetContents(); + + $this->expectException(\JsonSchema\Exception\ResourceNotFoundException::class); + $res->retrieve(__DIR__ . '/Fixture/missing.json'); } diff --git a/tests/Uri/Retrievers/PredefinedArrayTest.php b/tests/Uri/Retrievers/PredefinedArrayTest.php index 7ba0106d..84ecf3c7 100644 --- a/tests/Uri/Retrievers/PredefinedArrayTest.php +++ b/tests/Uri/Retrievers/PredefinedArrayTest.php @@ -29,11 +29,9 @@ public function testRetrieve() $this->assertEquals('THE_ADDRESS_SCHEMA', $this->retriever->retrieve('http://acme.com/schemas/address#')); } - /** - * @expectedException \JsonSchema\Exception\ResourceNotFoundException - */ public function testRetrieveNonExistsingSchema() { + $this->expectException(\JsonSchema\Exception\ResourceNotFoundException::class); $this->retriever->retrieve('http://acme.com/schemas/plop#'); } diff --git a/tests/Uri/UriResolverTest.php b/tests/Uri/UriResolverTest.php index 12624d90..49f5ac18 100644 --- a/tests/Uri/UriResolverTest.php +++ b/tests/Uri/UriResolverTest.php @@ -96,18 +96,11 @@ public function testResolveAbsoluteUri() ); } - /** - * @expectedException \JsonSchema\Exception\UriResolverException - */ + public function testResolveRelativeUriNoBase() { - $this->assertEquals( - 'http://example.org/foo/bar.json', - $this->resolver->resolve( - 'bar.json', - null - ) - ); + $this->expectException(\JsonSchema\Exception\UriResolverException::class); + $this->resolver->resolve('bar.json', null); } public function testResolveRelativeUriBaseDir() diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 3b76dfdc..b3576057 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -182,9 +182,6 @@ public function testResolvePointerFragment() ); } - /** - * @expectedException \JsonSchema\Exception\ResourceNotFoundException - */ public function testResolvePointerFragmentNotFound() { $schema = (object) array( @@ -197,14 +194,13 @@ public function testResolvePointerFragmentNotFound() ); $retriever = new UriRetriever(); + + $this->expectException(ResourceNotFoundException::class); $retriever->resolvePointer( $schema, 'http://example.org/schema.json#/definitions/bar' ); } - /** - * @expectedException \JsonSchema\Exception\ResourceNotFoundException - */ public function testResolvePointerFragmentNoArray() { $schema = (object) array( @@ -217,17 +213,18 @@ public function testResolvePointerFragmentNoArray() ); $retriever = new UriRetriever(); + + $this->expectException(ResourceNotFoundException::class); $retriever->resolvePointer( $schema, 'http://example.org/schema.json#/definitions/foo' ); } - /** - * @expectedException \JsonSchema\Exception\UriResolverException - */ public function testResolveExcessLevelUp() { $retriever = new UriRetriever(); + + $this->expectException(UriResolverException::class); $retriever->resolve( '../schema.json#', 'http://example.org/schema.json#' ); @@ -257,9 +254,6 @@ public function testConfirmMediaTypeAcceptsJsonType() $this->assertEquals(null, $retriever->confirmMediaType($uriRetriever, null)); } - /** - * @expectedException \JsonSchema\Exception\InvalidSchemaMediaTypeException - */ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() { $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); @@ -269,7 +263,9 @@ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() ->method('getContentType') ->willReturn('text/html'); - $this->assertEquals(null, $retriever->confirmMediaType($uriRetriever, null)); + $this->expectException(InvalidSchemaMediaTypeException::class); + + $retriever->confirmMediaType($uriRetriever, null); } private function mockRetriever($schema) @@ -343,15 +339,13 @@ public function testInvalidContentTypeEndpointsDefault() $this->assertTrue($retriever->confirmMediaType($mock, 'https://json-schema.org/')); } - /** - * @expectedException \JsonSchema\Exception\InvalidSchemaMediaTypeException - */ public function testInvalidContentTypeEndpointsUnknown() { $mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); + $this->expectException(InvalidSchemaMediaTypeException::class); $retriever->confirmMediaType($mock, 'http://example.com'); } From 0753efbadfc50675a1a0f9738041a0bfde6243dc Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 14:43:06 +0200 Subject: [PATCH 09/19] refactor: Replace assertInternalType for assertIsArray --- tests/Constraints/TypeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index 1c281f0b..c12ffd93 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -80,7 +80,7 @@ private function assertTypeConstraintError($expected, TypeConstraint $actual) $actualError = $actualErrors[0]; - $this->assertInternalType('array', $actualError, sprintf('Failed to assert that Type error is an array, %s given', gettype($actualError))); + $this->assertIsArray($actualError, sprintf('Failed to assert that Type error is an array, %s given', gettype($actualError))); $messageKey = 'message'; $this->assertArrayHasKey( From 524853abce52af4be2e6c5d06499dced64be61c3 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 14:44:06 +0200 Subject: [PATCH 10/19] refactor: Replace getMock for createMock --- tests/Uri/UriRetrieverTest.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index b3576057..8d67afa0 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -9,7 +9,10 @@ namespace JsonSchema\Tests\Uri; +use JsonSchema\Exception\InvalidSchemaMediaTypeException; use JsonSchema\Exception\JsonDecodingException; +use JsonSchema\Exception\ResourceNotFoundException; +use JsonSchema\Exception\UriResolverException; use JsonSchema\Uri\UriRetriever; use JsonSchema\Validator; use PHPUnit\Framework\TestCase; @@ -34,7 +37,7 @@ private function getRetrieverMock($returnSchema) throw new JsonDecodingException($error); } - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('retrieve')); + $retriever = $this->createMock('JsonSchema\Uri\UriRetriever'); $retriever->expects($this->at(0)) ->method('retrieve') @@ -232,7 +235,7 @@ public function testResolveExcessLevelUp() public function testConfirmMediaTypeAcceptsJsonSchemaType() { - $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $uriRetriever = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $retriever = new UriRetriever(); $uriRetriever->expects($this->at(0)) @@ -244,7 +247,7 @@ public function testConfirmMediaTypeAcceptsJsonSchemaType() public function testConfirmMediaTypeAcceptsJsonType() { - $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $uriRetriever = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $retriever = new UriRetriever(); $uriRetriever->expects($this->at(0)) @@ -256,9 +259,8 @@ public function testConfirmMediaTypeAcceptsJsonType() public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() { - $uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $uriRetriever = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $retriever = new UriRetriever(); - $uriRetriever->expects($this->at(0)) ->method('getContentType') ->willReturn('text/html'); @@ -331,7 +333,7 @@ public function testRetrieveSchemaFromPackage() public function testInvalidContentTypeEndpointsDefault() { - $mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $mock = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -341,7 +343,7 @@ public function testInvalidContentTypeEndpointsDefault() public function testInvalidContentTypeEndpointsUnknown() { - $mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $mock = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -351,7 +353,7 @@ public function testInvalidContentTypeEndpointsUnknown() public function testInvalidContentTypeEndpointsAdded() { - $mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $mock = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); $retriever->addInvalidContentTypeEndpoint('http://example.com'); From 97a5203ac8ed806747c4c3d5cf6ebd25e7541fb3 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 14:44:31 +0200 Subject: [PATCH 11/19] test: Improve test assertions --- tests/Constraints/TypeTest.php | 1 + tests/Uri/Retrievers/CurlTest.php | 8 ++++++-- tests/Uri/UriRetrieverTest.php | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index c12ffd93..ae35b449 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -116,6 +116,7 @@ public function testValidateTypeNameWording($nameWording) $m->setAccessible(true); $m->invoke($t, $nameWording); + $this->expectNotToPerformAssertions(); } public function testInvalidateTypeNameWording() diff --git a/tests/Uri/Retrievers/CurlTest.php b/tests/Uri/Retrievers/CurlTest.php index 431606b9..40293905 100644 --- a/tests/Uri/Retrievers/CurlTest.php +++ b/tests/Uri/Retrievers/CurlTest.php @@ -10,7 +10,9 @@ class CurlTest extends TestCase public function testRetrieveFile() { $c = new Curl(); - $c->retrieve(realpath(__DIR__ . '/../../fixtures/foobar.json')); + $result = $c->retrieve(realpath(__DIR__ . '/../../fixtures/foobar.json')); + + self::assertStringEqualsFileCanonicalizing(realpath(__DIR__ . '/../../fixtures/foobar.json'), $result); } public function testRetrieveNonexistantFile() @@ -26,7 +28,9 @@ public function testRetrieveNonexistantFile() public function testNoContentType() { $c = new Curl(); - $c->retrieve(realpath(__DIR__ . '/../../fixtures') . '/foobar-noheader.json'); + $result = $c->retrieve(realpath(__DIR__ . '/../../fixtures') . '/foobar-noheader.json'); + + self::assertStringEqualsFileCanonicalizing(realpath(__DIR__ . '/../../fixtures/foobar.json'), $result); } } } diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 8d67afa0..21de96dc 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -358,7 +358,9 @@ public function testInvalidContentTypeEndpointsAdded() $retriever = new UriRetriever(); $retriever->addInvalidContentTypeEndpoint('http://example.com'); - $retriever->confirmMediaType($mock, 'http://example.com'); + $result = $retriever->confirmMediaType($mock, 'http://example.com'); + + self::assertTrue($result); } public function testSchemaCache() From 4e77e276cb50a6eca61e280b35c436b8fa2072e6 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 14:58:09 +0200 Subject: [PATCH 12/19] fix: Solve return type issues with Objectiterator (port of #682) See https://github.com/jsonrainbow/json-schema/pull/682 --- src/JsonSchema/Iterator/ObjectIterator.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/JsonSchema/Iterator/ObjectIterator.php b/src/JsonSchema/Iterator/ObjectIterator.php index c459713b..12dd1c11 100644 --- a/src/JsonSchema/Iterator/ObjectIterator.php +++ b/src/JsonSchema/Iterator/ObjectIterator.php @@ -39,6 +39,7 @@ public function __construct($object) /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function current() { $this->initialize(); @@ -49,7 +50,7 @@ public function current() /** * {@inheritdoc} */ - public function next() + public function next(): void { $this->initialize(); $this->position++; @@ -58,7 +59,7 @@ public function next() /** * {@inheritdoc} */ - public function key() + public function key(): int { $this->initialize(); @@ -68,7 +69,7 @@ public function key() /** * {@inheritdoc} */ - public function valid() + public function valid(): bool { $this->initialize(); @@ -78,7 +79,7 @@ public function valid() /** * {@inheritdoc} */ - public function rewind() + public function rewind(): void { $this->initialize(); $this->position = 0; @@ -87,7 +88,7 @@ public function rewind() /** * {@inheritdoc} */ - public function count() + public function count(): int { $this->initialize(); From db8111be74709af855aeac86398bb23286f727f4 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 15:32:37 +0200 Subject: [PATCH 13/19] build: Update icecave/parity to ^3.0 as 1.0 uses deprecated each() method --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1e79a522..946fb395 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require": { "php": "^7.2 || ^8.0", "marc-mabe/php-enum":"^2.0 || ^3.0 || ^4.0", - "icecave/parity": "1.0.0" + "icecave/parity": "^3.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "~2.2.20 || ~2.19.0", From 6448d43ac7c9103a2ec43136363ccc162c355d6c Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 15:37:14 +0200 Subject: [PATCH 14/19] style: Correct code style issues --- tests/Uri/UriResolverTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Uri/UriResolverTest.php b/tests/Uri/UriResolverTest.php index 49f5ac18..38274409 100644 --- a/tests/Uri/UriResolverTest.php +++ b/tests/Uri/UriResolverTest.php @@ -96,7 +96,6 @@ public function testResolveAbsoluteUri() ); } - public function testResolveRelativeUriNoBase() { $this->expectException(\JsonSchema\Exception\UriResolverException::class); From ac94ea5d6135cbd404bd1e0604e2a525cf6ecf09 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 16:07:33 +0200 Subject: [PATCH 15/19] fix: Fix deprecation notices found from GHA workflow run See https://github.com/jsonrainbow/json-schema/actions/runs/10216569969/job/28268331091 --- src/JsonSchema/Uri/UriRetriever.php | 2 +- tests/Uri/UriRetrieverTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JsonSchema/Uri/UriRetriever.php b/src/JsonSchema/Uri/UriRetriever.php index 41147a2a..ab08e8a3 100644 --- a/src/JsonSchema/Uri/UriRetriever.php +++ b/src/JsonSchema/Uri/UriRetriever.php @@ -84,7 +84,7 @@ public function confirmMediaType($uriRetriever, $uri) } foreach ($this->allowedInvalidContentTypeEndpoints as $endpoint) { - if (strpos($uri, $endpoint) === 0) { + if (!\is_null($uri) && strpos($uri, $endpoint) === 0) { return true; } } diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 21de96dc..b494dcd1 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -300,7 +300,7 @@ public function testPackageURITranslation() $root = sprintf('file://%s/', realpath(__DIR__ . '/../..')); $uri = $retriever->translate('package://foo/bar.json'); - $this->assertEquals("${root}foo/bar.json", $uri); + $this->assertEquals("{$root}foo/bar.json", $uri); } public function testDefaultDistTranslations() From 5224ee955a62001f038128e3eea051f4d1cb35fa Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 16:19:23 +0200 Subject: [PATCH 16/19] fix: Add fallback to empty string when null value is passed in UriResolver::parse --- src/JsonSchema/Uri/UriResolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonSchema/Uri/UriResolver.php b/src/JsonSchema/Uri/UriResolver.php index 8ab6650e..f9c58982 100644 --- a/src/JsonSchema/Uri/UriResolver.php +++ b/src/JsonSchema/Uri/UriResolver.php @@ -28,7 +28,7 @@ class UriResolver implements UriResolverInterface */ public function parse($uri) { - preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match); + preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri ?: '', $match); $components = array(); if (5 < count($match)) { From 24b343b980ca5342482e74fd8cbaee9521045d59 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 16:39:08 +0200 Subject: [PATCH 17/19] test: Verbose output to get a hint why test are being skipped --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 946fb395..12013538 100644 --- a/composer.json +++ b/composer.json @@ -73,7 +73,7 @@ "coverage": "phpunit --coverage-text", "style-check": "php-cs-fixer fix --dry-run --verbose --diff", "style-fix": "php-cs-fixer fix --verbose", - "test": "phpunit", + "test": "phpunit --verbose", "testOnly": "phpunit --colors --filter" } } From 8d291721cd717123074b187efba50cf853c6208f Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 16:55:34 +0200 Subject: [PATCH 18/19] fix: Correct path for case-sensitive operating systems --- tests/Drafts/BaseDraftTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Drafts/BaseDraftTestCase.php b/tests/Drafts/BaseDraftTestCase.php index 1cfe634c..8af703e7 100644 --- a/tests/Drafts/BaseDraftTestCase.php +++ b/tests/Drafts/BaseDraftTestCase.php @@ -10,7 +10,7 @@ abstract class BaseDraftTestCase extends BaseTestCase { /** @var string */ - protected $relativeTestsRoot = '/../../vendor/json-schema/JSON-Schema-Test-Suite/tests'; + protected $relativeTestsRoot = '/../../vendor/json-schema/json-schema-test-suite/tests'; private function setUpTests($isValid) { From 24b5b4f4c1f55aa9c1288e2aa06407ca35de3dd1 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 2 Aug 2024 22:14:15 +0200 Subject: [PATCH 19/19] fix: Correct path for case-sensitive operating systems --- tests/Constraints/VeryBaseTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Constraints/VeryBaseTestCase.php b/tests/Constraints/VeryBaseTestCase.php index 7cd7c06b..f12cba88 100644 --- a/tests/Constraints/VeryBaseTestCase.php +++ b/tests/Constraints/VeryBaseTestCase.php @@ -30,7 +30,7 @@ abstract class VeryBaseTestCase extends TestCase */ protected function getUriRetrieverMock($schema) { - $relativeTestsRoot = realpath(__DIR__ . '/../../vendor/json-schema/JSON-Schema-Test-Suite/remotes'); + $relativeTestsRoot = realpath(__DIR__ . '/../../vendor/json-schema/json-schema-test-suite/remotes'); $jsonSchemaDraft03 = $this->getJsonSchemaDraft03(); $jsonSchemaDraft04 = $this->getJsonSchemaDraft04();