diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index f11ebd4e..5da22712 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -17,34 +17,35 @@ jobs: strategy: matrix: php-version: - - "5.3" - - "5.4" - - "5.5" - - "5.6" - - "7.0" - - "7.1" + # - "5.3" + # - "5.4" + # - "5.5" + # - "5.6" + # - "7.0" + # - "7.1" - "7.2" - "7.3" - "7.4" -# - "8.0" + - "8.0" + - "8.1" dependencies: [highest] experimental: [false] include: - - php-version: "5.3" - dependencies: highest - experimental: false - - php-version: "5.3" - dependencies: lowest - experimental: false -# - php-version: "8.0" -# dependencies: highest -# experimental: false -# - php-version: "8.1" -# dependencies: lowest-ignore -# experimental: true -# - php-version: "8.1" -# dependencies: highest-ignore -# experimental: true + # - php-version: "5.3" + # dependencies: highest + # experimental: false + # - php-version: "5.3" + # dependencies: lowest + # experimental: false + - php-version: "8.0" + dependencies: highest + experimental: false + - php-version: "8.1" + dependencies: lowest-ignore + experimental: true + - php-version: "8.1" + dependencies: highest-ignore + experimental: true steps: - name: "Checkout" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b983c4da..8d65da85 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: diff --git a/composer.json b/composer.json index f1b69142..76ccbb34 100644 --- a/composer.json +++ b/composer.json @@ -27,14 +27,14 @@ } ], "require": { - "php": ">=5.3.3", + "php": ">=7.2", "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", "json-schema/json-schema-test-suite": "1.2.0", - "phpunit/phpunit": "^4.8.35" + "phpunit/phpunit": "^8.5.26" }, "extra": { "branch-alias": { diff --git a/src/JsonSchema/Iterator/ObjectIterator.php b/src/JsonSchema/Iterator/ObjectIterator.php index c459713b..391be792 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,6 +59,7 @@ public function next() /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function key() { $this->initialize(); @@ -68,7 +70,7 @@ public function key() /** * {@inheritdoc} */ - public function valid() + public function valid(): bool { $this->initialize(); @@ -78,7 +80,7 @@ public function valid() /** * {@inheritdoc} */ - public function rewind() + public function rewind(): void { $this->initialize(); $this->position = 0; @@ -87,7 +89,7 @@ public function rewind() /** * {@inheritdoc} */ - public function count() + public function count(): int { $this->initialize(); diff --git a/src/JsonSchema/Uri/UriResolver.php b/src/JsonSchema/Uri/UriResolver.php index 8ab6650e..d2534aa3 100644 --- a/src/JsonSchema/Uri/UriResolver.php +++ b/src/JsonSchema/Uri/UriResolver.php @@ -28,6 +28,10 @@ class UriResolver implements UriResolverInterface */ public function parse($uri) { + if (null === $uri || '' === $uri) { + return array(); + } + preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match); $components = array(); @@ -102,7 +106,7 @@ public function resolve($uri, $baseUri = null) return $uri; } $baseComponents = $this->parse($baseUri); - $basePath = $baseComponents['path']; + $basePath = $baseComponents['path'] ?? ''; $baseComponents['path'] = self::combineRelativePathWithBasePath($path, $basePath); if (isset($components['fragment'])) { diff --git a/src/JsonSchema/Uri/UriRetriever.php b/src/JsonSchema/Uri/UriRetriever.php index 41147a2a..4dfa0d05 100644 --- a/src/JsonSchema/Uri/UriRetriever.php +++ b/src/JsonSchema/Uri/UriRetriever.php @@ -83,9 +83,11 @@ public function confirmMediaType($uriRetriever, $uri) return; } - foreach ($this->allowedInvalidContentTypeEndpoints as $endpoint) { - if (strpos($uri, $endpoint) === 0) { - return true; + if (null !== $uri) { + foreach ($this->allowedInvalidContentTypeEndpoints as $endpoint) { + if (strpos($uri, $endpoint) === 0) { + return true; + } } } diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index bd0082f0..079051a3 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::class); + $this->expectExceptionMessage('Missing error message for missingError'); + $e->getMessage(); } } 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..d3591354 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(); } @@ -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/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/Constraints/SchemaValidationTest.php b/tests/Constraints/SchemaValidationTest.php index 85907c5d..3a2efc28 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -102,19 +102,15 @@ 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..c2d6cbff 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -125,10 +125,8 @@ 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 +136,8 @@ 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..b5c0a5a8 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -113,10 +113,8 @@ 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/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/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..014b5c8f 100644 --- a/tests/Uri/Retrievers/CurlTest.php +++ b/tests/Uri/Retrievers/CurlTest.php @@ -17,10 +17,8 @@ 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/Retrievers/FileGetContentsTest.php b/tests/Uri/Retrievers/FileGetContentsTest.php index 0514a7d5..0b7eef59 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -30,10 +30,8 @@ public function testFalseReturn() { $res = new FileGetContents(); - $this->setExpectedException( - '\JsonSchema\Exception\ResourceNotFoundException', - 'JSON schema not found at http://example.com/false' - ); + $this->expectException('\JsonSchema\Exception\ResourceNotFoundException'); + $this->expectExceptionMessage('JSON schema not found at http://example.com/false'); $res->retrieve('http://example.com/false'); } @@ -41,10 +39,8 @@ public function testFetchDirectory() { $res = new FileGetContents(); - $this->setExpectedException( - '\JsonSchema\Exception\ResourceNotFoundException', - 'JSON schema not found at file:///this/is/a/directory/' - ); + $this->expectException('\JsonSchema\Exception\ResourceNotFoundException'); + $this->expectExceptionMessage('JSON schema not found at file:///this/is/a/directory/'); $res->retrieve('file:///this/is/a/directory/'); } 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 a353de50..3c3eb9c8 100644 --- a/tests/Uri/UriResolverTest.php +++ b/tests/Uri/UriResolverTest.php @@ -7,7 +7,7 @@ class UriResolverTest extends TestCase { - public function setUp() + public function setUp(): void { $this->resolver = new UriResolver(); } diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 24714a26..f30c4564 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(); } @@ -34,7 +34,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') @@ -235,24 +235,26 @@ public function testResolveExcessLevelUp() public function testConfirmMediaTypeAcceptsJsonSchemaType() { - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retrieverUri = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); + $retrieverUri->expects($this->at(0)) + ->method('getContentType') + ->will($this->returnValue('application/schema+json')); - $retriever->expects($this->at(0)) - ->method('getContentType') - ->will($this->returnValue('application/schema+json')); + $retriever = new \JsonSchema\Uri\UriRetriever(); - $this->assertEquals(null, $retriever->confirmMediaType($retriever, null)); + $this->assertEquals(null, $retriever->confirmMediaType($retrieverUri, null)); } public function testConfirmMediaTypeAcceptsJsonType() { - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retrieverUri = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); + $retrieverUri->expects($this->at(0)) + ->method('getContentType') + ->will($this->returnValue('application/json')); - $retriever->expects($this->at(0)) - ->method('getContentType') - ->will($this->returnValue('application/json')); + $retriever = new \JsonSchema\Uri\UriRetriever(); - $this->assertEquals(null, $retriever->confirmMediaType($retriever, null)); + $this->assertEquals(null, $retriever->confirmMediaType($retrieverUri, null)); } /** @@ -260,13 +262,14 @@ public function testConfirmMediaTypeAcceptsJsonType() */ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() { - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retrieverUri = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); + $retrieverUri->expects($this->at(0)) + ->method('getContentType') + ->will($this->returnValue('text/html')); - $retriever->expects($this->at(0)) - ->method('getContentType') - ->will($this->returnValue('text/html')); + $retriever = new \JsonSchema\Uri\UriRetriever(); - $this->assertEquals(null, $retriever->confirmMediaType($retriever, null)); + $this->assertEquals(null, $retriever->confirmMediaType($retrieverUri, null)); } private function mockRetriever($schema) @@ -332,7 +335,7 @@ public function testRetrieveSchemaFromPackage() public function testInvalidContentTypeEndpointsDefault() { - $mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -345,7 +348,7 @@ public function testInvalidContentTypeEndpointsDefault() */ public function testInvalidContentTypeEndpointsUnknown() { - $mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -354,7 +357,7 @@ public function testInvalidContentTypeEndpointsUnknown() public function testInvalidContentTypeEndpointsAdded() { - $mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); $retriever->addInvalidContentTypeEndpoint('http://example.com'); @@ -385,10 +388,8 @@ 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'); $schema = $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); }