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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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 bd4d321e5b98d51ab835daf78a57018d8dd19d06 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 9 Aug 2024 09:38:53 +0200 Subject: [PATCH 17/20] fix: Port #717: Fixes for implicit nullability deprecation See https://github.com/jsonrainbow/json-schema/pull/717 --- src/JsonSchema/Constraints/BaseConstraint.php | 4 +-- .../Constraints/CollectionConstraint.php | 4 +-- .../Constraints/ConstConstraint.php | 2 +- src/JsonSchema/Constraints/Constraint.php | 28 +++++++++---------- .../Constraints/ConstraintInterface.php | 4 +-- src/JsonSchema/Constraints/EnumConstraint.php | 2 +- src/JsonSchema/Constraints/Factory.php | 10 +++---- .../Constraints/FormatConstraint.php | 2 +- .../Constraints/NumberConstraint.php | 2 +- .../Constraints/ObjectConstraint.php | 10 +++---- .../Constraints/SchemaConstraint.php | 2 +- .../Constraints/StringConstraint.php | 2 +- src/JsonSchema/Constraints/TypeConstraint.php | 2 +- .../Constraints/UndefinedConstraint.php | 2 +- .../Exception/JsonDecodingException.php | 2 +- src/JsonSchema/SchemaStorage.php | 4 +-- tests/Constraints/FactoryTest.php | 2 +- 17 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/JsonSchema/Constraints/BaseConstraint.php b/src/JsonSchema/Constraints/BaseConstraint.php index 2e8339da..bd07d70f 100644 --- a/src/JsonSchema/Constraints/BaseConstraint.php +++ b/src/JsonSchema/Constraints/BaseConstraint.php @@ -39,12 +39,12 @@ class BaseConstraint /** * @param Factory $factory */ - public function __construct(Factory $factory = null) + public function __construct(?Factory $factory = null) { $this->factory = $factory ?: new Factory(); } - public function addError(ConstraintError $constraint, JsonPointer $path = null, array $more = array()) + public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = array()) { $message = $constraint ? $constraint->getMessage() : ''; $name = $constraint ? $constraint->getValue() : ''; diff --git a/src/JsonSchema/Constraints/CollectionConstraint.php b/src/JsonSchema/Constraints/CollectionConstraint.php index 825d4531..98aad564 100644 --- a/src/JsonSchema/Constraints/CollectionConstraint.php +++ b/src/JsonSchema/Constraints/CollectionConstraint.php @@ -23,7 +23,7 @@ class CollectionConstraint extends Constraint /** * {@inheritdoc} */ - public function check(&$value, $schema = null, JsonPointer $path = null, $i = null) + public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null) { // Verify minItems if (isset($schema->minItems) && count($value) < $schema->minItems) { @@ -62,7 +62,7 @@ public function check(&$value, $schema = null, JsonPointer $path = null, $i = nu * @param JsonPointer|null $path * @param string $i */ - protected function validateItems(&$value, $schema = null, JsonPointer $path = null, $i = null) + protected function validateItems(&$value, $schema = null, ?JsonPointer $path = null, $i = null) { if (is_object($schema->items)) { // just one type definition for the whole array diff --git a/src/JsonSchema/Constraints/ConstConstraint.php b/src/JsonSchema/Constraints/ConstConstraint.php index b0fa39c0..80c45cca 100644 --- a/src/JsonSchema/Constraints/ConstConstraint.php +++ b/src/JsonSchema/Constraints/ConstConstraint.php @@ -23,7 +23,7 @@ class ConstConstraint extends Constraint /** * {@inheritdoc} */ - public function check(&$element, $schema = null, JsonPointer $path = null, $i = null) + public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null) { // Only validate const if the attribute exists if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) { diff --git a/src/JsonSchema/Constraints/Constraint.php b/src/JsonSchema/Constraints/Constraint.php index d088fd49..8a988cda 100644 --- a/src/JsonSchema/Constraints/Constraint.php +++ b/src/JsonSchema/Constraints/Constraint.php @@ -40,7 +40,7 @@ abstract class Constraint extends BaseConstraint implements ConstraintInterface * * @return JsonPointer; */ - protected function incrementPath(JsonPointer $path = null, $i) + protected function incrementPath(?JsonPointer $path = null, $i) { $path = $path ?: new JsonPointer(''); @@ -66,7 +66,7 @@ protected function incrementPath(JsonPointer $path = null, $i) * @param JsonPointer|null $path * @param mixed $i */ - protected function checkArray(&$value, $schema = null, JsonPointer $path = null, $i = null) + protected function checkArray(&$value, $schema = null, ?JsonPointer $path = null, $i = null) { $validator = $this->factory->createInstanceFor('collection'); $validator->check($value, $schema, $path, $i); @@ -84,7 +84,7 @@ protected function checkArray(&$value, $schema = null, JsonPointer $path = null, * @param mixed $additionalProperties * @param mixed $patternProperties */ - protected function checkObject(&$value, $schema = null, JsonPointer $path = null, $properties = null, + protected function checkObject(&$value, $schema = null, ?JsonPointer $path = null, $properties = null, $additionalProperties = null, $patternProperties = null, $appliedDefaults = array()) { /** @var ObjectConstraint $validator */ @@ -102,7 +102,7 @@ protected function checkObject(&$value, $schema = null, JsonPointer $path = null * @param JsonPointer|null $path * @param mixed $i */ - protected function checkType(&$value, $schema = null, JsonPointer $path = null, $i = null) + protected function checkType(&$value, $schema = null, ?JsonPointer $path = null, $i = null) { $validator = $this->factory->createInstanceFor('type'); $validator->check($value, $schema, $path, $i); @@ -118,7 +118,7 @@ protected function checkType(&$value, $schema = null, JsonPointer $path = null, * @param JsonPointer|null $path * @param mixed $i */ - protected function checkUndefined(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false) + protected function checkUndefined(&$value, $schema = null, ?JsonPointer $path = null, $i = null, $fromDefault = false) { /** @var UndefinedConstraint $validator */ $validator = $this->factory->createInstanceFor('undefined'); @@ -136,7 +136,7 @@ protected function checkUndefined(&$value, $schema = null, JsonPointer $path = n * @param JsonPointer|null $path * @param mixed $i */ - protected function checkString($value, $schema = null, JsonPointer $path = null, $i = null) + protected function checkString($value, $schema = null, ?JsonPointer $path = null, $i = null) { $validator = $this->factory->createInstanceFor('string'); $validator->check($value, $schema, $path, $i); @@ -147,12 +147,12 @@ protected function checkString($value, $schema = null, JsonPointer $path = null, /** * Checks a number element * - * @param mixed $value - * @param mixed $schema - * @param JsonPointer $path - * @param mixed $i + * @param mixed $value + * @param mixed $schema + * @param JsonPointer|null $path + * @param mixed $i */ - protected function checkNumber($value, $schema = null, JsonPointer $path = null, $i = null) + protected function checkNumber($value, $schema = null, ?JsonPointer $path = null, $i = null) { $validator = $this->factory->createInstanceFor('number'); $validator->check($value, $schema, $path, $i); @@ -168,7 +168,7 @@ protected function checkNumber($value, $schema = null, JsonPointer $path = null, * @param JsonPointer|null $path * @param mixed $i */ - protected function checkEnum($value, $schema = null, JsonPointer $path = null, $i = null) + protected function checkEnum($value, $schema = null, ?JsonPointer $path = null, $i = null) { $validator = $this->factory->createInstanceFor('enum'); $validator->check($value, $schema, $path, $i); @@ -184,7 +184,7 @@ protected function checkEnum($value, $schema = null, JsonPointer $path = null, $ * @param JsonPointer|null $path * @param mixed $i */ - protected function checkConst($value, $schema = null, JsonPointer $path = null, $i = null) + protected function checkConst($value, $schema = null, ?JsonPointer $path = null, $i = null) { $validator = $this->factory->createInstanceFor('const'); $validator->check($value, $schema, $path, $i); @@ -200,7 +200,7 @@ protected function checkConst($value, $schema = null, JsonPointer $path = null, * @param JsonPointer|null $path * @param mixed $i */ - protected function checkFormat($value, $schema = null, JsonPointer $path = null, $i = null) + protected function checkFormat($value, $schema = null, ?JsonPointer $path = null, $i = null) { $validator = $this->factory->createInstanceFor('format'); $validator->check($value, $schema, $path, $i); diff --git a/src/JsonSchema/Constraints/ConstraintInterface.php b/src/JsonSchema/Constraints/ConstraintInterface.php index a1b5aa97..209e5712 100644 --- a/src/JsonSchema/Constraints/ConstraintInterface.php +++ b/src/JsonSchema/Constraints/ConstraintInterface.php @@ -40,7 +40,7 @@ public function addErrors(array $errors); * @param JsonPointer|null $path * @param array $more more array elements to add to the error */ - public function addError(ConstraintError $constraint, JsonPointer $path = null, array $more = array()); + public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = array()); /** * checks if the validator has not raised errors @@ -61,5 +61,5 @@ public function isValid(); * * @throws \JsonSchema\Exception\ExceptionInterface */ - public function check(&$value, $schema = null, JsonPointer $path = null, $i = null); + public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null); } diff --git a/src/JsonSchema/Constraints/EnumConstraint.php b/src/JsonSchema/Constraints/EnumConstraint.php index a66d04a7..73fb8d24 100644 --- a/src/JsonSchema/Constraints/EnumConstraint.php +++ b/src/JsonSchema/Constraints/EnumConstraint.php @@ -24,7 +24,7 @@ class EnumConstraint extends Constraint /** * {@inheritdoc} */ - public function check(&$element, $schema = null, JsonPointer $path = null, $i = null) + public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null) { // Only validate enum if the attribute exists if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) { diff --git a/src/JsonSchema/Constraints/Factory.php b/src/JsonSchema/Constraints/Factory.php index 0895b265..5f798c99 100644 --- a/src/JsonSchema/Constraints/Factory.php +++ b/src/JsonSchema/Constraints/Factory.php @@ -70,13 +70,13 @@ class Factory private $instanceCache = array(); /** - * @param SchemaStorage $schemaStorage - * @param UriRetrieverInterface $uriRetriever - * @param int $checkMode + * @param ?SchemaStorage $schemaStorage + * @param ?UriRetrieverInterface $uriRetriever + * @param int $checkMode */ public function __construct( - SchemaStorageInterface $schemaStorage = null, - UriRetrieverInterface $uriRetriever = null, + ?SchemaStorageInterface $schemaStorage = null, + ?UriRetrieverInterface $uriRetriever = null, $checkMode = Constraint::CHECK_MODE_NORMAL ) { // set provided config options diff --git a/src/JsonSchema/Constraints/FormatConstraint.php b/src/JsonSchema/Constraints/FormatConstraint.php index ebc791bb..a302573f 100644 --- a/src/JsonSchema/Constraints/FormatConstraint.php +++ b/src/JsonSchema/Constraints/FormatConstraint.php @@ -25,7 +25,7 @@ class FormatConstraint extends Constraint /** * {@inheritdoc} */ - public function check(&$element, $schema = null, JsonPointer $path = null, $i = null) + public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null) { if (!isset($schema->format) || $this->factory->getConfig(self::CHECK_MODE_DISABLE_FORMAT)) { return; diff --git a/src/JsonSchema/Constraints/NumberConstraint.php b/src/JsonSchema/Constraints/NumberConstraint.php index c1b15f94..80b9d4dd 100644 --- a/src/JsonSchema/Constraints/NumberConstraint.php +++ b/src/JsonSchema/Constraints/NumberConstraint.php @@ -23,7 +23,7 @@ class NumberConstraint extends Constraint /** * {@inheritdoc} */ - public function check(&$element, $schema = null, JsonPointer $path = null, $i = null) + public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null) { // Verify minimum if (isset($schema->exclusiveMinimum)) { diff --git a/src/JsonSchema/Constraints/ObjectConstraint.php b/src/JsonSchema/Constraints/ObjectConstraint.php index b4f85650..d633f372 100644 --- a/src/JsonSchema/Constraints/ObjectConstraint.php +++ b/src/JsonSchema/Constraints/ObjectConstraint.php @@ -28,7 +28,7 @@ class ObjectConstraint extends Constraint /** * {@inheritdoc} */ - public function check(&$element, $schema = null, JsonPointer $path = null, $properties = null, + public function check(&$element, $schema = null, ?JsonPointer $path = null, $properties = null, $additionalProp = null, $patternProperties = null, $appliedDefaults = array()) { if ($element instanceof UndefinedConstraint) { @@ -52,7 +52,7 @@ public function check(&$element, $schema = null, JsonPointer $path = null, $prop $this->validateElement($element, $matches, $schema, $path, $properties, $additionalProp); } - public function validatePatternProperties($element, JsonPointer $path = null, $patternProperties) + public function validatePatternProperties($element, ?JsonPointer $path = null, $patternProperties) { $matches = array(); foreach ($patternProperties as $pregex => $schema) { @@ -84,7 +84,7 @@ public function validatePatternProperties($element, JsonPointer $path = null, $p * @param \StdClass $properties Properties * @param mixed $additionalProp Additional properties */ - public function validateElement($element, $matches, $schema = null, JsonPointer $path = null, + public function validateElement($element, $matches, $schema = null, ?JsonPointer $path = null, $properties = null, $additionalProp = null) { $this->validateMinMaxConstraint($element, $schema, $path); @@ -129,7 +129,7 @@ public function validateElement($element, $matches, $schema = null, JsonPointer * @param \stdClass $properties Property definitions * @param JsonPointer|null $path Path? */ - public function validateProperties(&$element, $properties = null, JsonPointer $path = null) + public function validateProperties(&$element, $properties = null, ?JsonPointer $path = null) { $undefinedConstraint = $this->factory->createInstanceFor('undefined'); @@ -171,7 +171,7 @@ protected function &getProperty(&$element, $property, $fallback = null) * @param \stdClass $objectDefinition ObjectConstraint definition * @param JsonPointer|null $path Path to test? */ - protected function validateMinMaxConstraint($element, $objectDefinition, JsonPointer $path = null) + protected function validateMinMaxConstraint($element, $objectDefinition, ?JsonPointer $path = null) { // Verify minimum number of properties if (isset($objectDefinition->minProperties) && !is_object($objectDefinition->minProperties)) { diff --git a/src/JsonSchema/Constraints/SchemaConstraint.php b/src/JsonSchema/Constraints/SchemaConstraint.php index 425c38f2..b804e6b0 100644 --- a/src/JsonSchema/Constraints/SchemaConstraint.php +++ b/src/JsonSchema/Constraints/SchemaConstraint.php @@ -29,7 +29,7 @@ class SchemaConstraint extends Constraint /** * {@inheritdoc} */ - public function check(&$element, $schema = null, JsonPointer $path = null, $i = null) + public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null) { if ($schema !== null) { // passed schema diff --git a/src/JsonSchema/Constraints/StringConstraint.php b/src/JsonSchema/Constraints/StringConstraint.php index 1ccb23b0..29981f23 100644 --- a/src/JsonSchema/Constraints/StringConstraint.php +++ b/src/JsonSchema/Constraints/StringConstraint.php @@ -23,7 +23,7 @@ class StringConstraint extends Constraint /** * {@inheritdoc} */ - public function check(&$element, $schema = null, JsonPointer $path = null, $i = null) + public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null) { // Verify maxLength if (isset($schema->maxLength) && $this->strlen($element) > $schema->maxLength) { diff --git a/src/JsonSchema/Constraints/TypeConstraint.php b/src/JsonSchema/Constraints/TypeConstraint.php index be8e0672..c7a0b593 100644 --- a/src/JsonSchema/Constraints/TypeConstraint.php +++ b/src/JsonSchema/Constraints/TypeConstraint.php @@ -40,7 +40,7 @@ class TypeConstraint extends Constraint /** * {@inheritdoc} */ - public function check(&$value = null, $schema = null, JsonPointer $path = null, $i = null) + public function check(&$value = null, $schema = null, ?JsonPointer $path = null, $i = null) { $type = isset($schema->type) ? $schema->type : null; $isValid = false; diff --git a/src/JsonSchema/Constraints/UndefinedConstraint.php b/src/JsonSchema/Constraints/UndefinedConstraint.php index aa5e664f..6b4ad5e8 100644 --- a/src/JsonSchema/Constraints/UndefinedConstraint.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -32,7 +32,7 @@ class UndefinedConstraint extends Constraint /** * {@inheritdoc} */ - public function check(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false) + public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null, $fromDefault = false) { if (is_null($schema) || !is_object($schema)) { return; diff --git a/src/JsonSchema/Exception/JsonDecodingException.php b/src/JsonSchema/Exception/JsonDecodingException.php index c7719828..7641f61b 100644 --- a/src/JsonSchema/Exception/JsonDecodingException.php +++ b/src/JsonSchema/Exception/JsonDecodingException.php @@ -14,7 +14,7 @@ */ class JsonDecodingException extends RuntimeException { - public function __construct($code = JSON_ERROR_NONE, \Exception $previous = null) + public function __construct($code = JSON_ERROR_NONE, ?\Exception $previous = null) { switch ($code) { case JSON_ERROR_DEPTH: diff --git a/src/JsonSchema/SchemaStorage.php b/src/JsonSchema/SchemaStorage.php index 81b3508c..4e407413 100644 --- a/src/JsonSchema/SchemaStorage.php +++ b/src/JsonSchema/SchemaStorage.php @@ -17,8 +17,8 @@ class SchemaStorage implements SchemaStorageInterface protected $schemas = array(); public function __construct( - UriRetrieverInterface $uriRetriever = null, - UriResolverInterface $uriResolver = null + ?UriRetrieverInterface $uriRetriever = null, + ?UriResolverInterface $uriResolver = null ) { $this->uriRetriever = $uriRetriever ?: new UriRetriever(); $this->uriResolver = $uriResolver ?: new UriResolver(); diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index ac573d3f..ea65e246 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -30,7 +30,7 @@ class MyBadConstraint */ class MyStringConstraint extends Constraint { - public function check(&$value, $schema = null, JsonPointer $path = null, $i = null) + public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null) { } } From 7f8d75a342d73b359a5ac9c45875a3ca852c7ae5 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 9 Aug 2024 09:39:44 +0200 Subject: [PATCH 18/20] ci: Avoid GHA run on each push and pull request; Include PHP 8.4 in matrix --- .github/workflows/continuous-integration.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e45c7726..371e033e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,8 +1,12 @@ name: "Continuous Integration" on: - - push - - pull_request + push: + branches: + - master + pull_request: + branches: + - master env: COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist" @@ -24,6 +28,7 @@ jobs: - "8.1" - "8.2" - "8.3" + - "8.4" dependencies: [highest] experimental: [false] include: From b611aebd127e2d63a7e68da6fb4afc26ff65ec3f Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 9 Aug 2024 09:47:15 +0200 Subject: [PATCH 19/20] ci(Drop-PHP-8.4-from-matrix): This PR adds phpspec/prophecy as an explicit dependency which is restrictive and doesnt support upcoming PHP versions --- .github/workflows/continuous-integration.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 371e033e..e7a35e85 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -28,7 +28,6 @@ jobs: - "8.1" - "8.2" - "8.3" - - "8.4" dependencies: [highest] experimental: [false] include: From b554f788d4f5f6756abf78fec7de875c301019da Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 27 Aug 2024 08:45:10 +0200 Subject: [PATCH 20/20] refactor: Replace ternary variable with explicit cast to string --- 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 f9c58982..9785146d 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('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', (string) $uri, $match); $components = array(); if (5 < count($match)) {