diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a72829ed..e45c7726 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -17,23 +17,20 @@ jobs: strategy: matrix: php-version: - - "5.3" - - "5.4" - - "5.5" - - "5.6" - - "7.0" - - "7.1" - "7.2" - "7.3" - "7.4" -# - "8.0" + - "8.0" + - "8.1" + - "8.2" + - "8.3" 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: diff --git a/composer.json b/composer.json index 827cff0d..12013538 100644 --- a/composer.json +++ b/composer.json @@ -27,14 +27,15 @@ } ], "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" + "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", + "phpspec/prophecy": "^1.19" }, "extra": { "branch-alias": { @@ -72,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" } } 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 @@ - 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(); 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)) { 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/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/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..ac573d3f 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); } @@ -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/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..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..ae35b449 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( @@ -116,6 +116,7 @@ public function testValidateTypeNameWording($nameWording) $m->setAccessible(true); $m->invoke($t, $nameWording); + $this->expectNotToPerformAssertions(); } public function testInvalidateTypeNameWording() @@ -125,10 +126,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 +138,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/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(); 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) { 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/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..40293905 100644 --- a/tests/Uri/Retrievers/CurlTest.php +++ b/tests/Uri/Retrievers/CurlTest.php @@ -10,24 +10,27 @@ 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() { $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'); } 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/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 7684bb1f..84ecf3c7 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( @@ -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 b0207cb7..38274409 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(); } @@ -96,18 +96,10 @@ 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 3c500699..b494dcd1 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; @@ -21,7 +24,7 @@ class UriRetrieverTest extends TestCase { protected $validator; - protected function setUp() + protected function setUp(): void { $this->validator = new Validator(); } @@ -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') @@ -182,9 +185,6 @@ public function testResolvePointerFragment() ); } - /** - * @expectedException \JsonSchema\Exception\ResourceNotFoundException - */ public function testResolvePointerFragmentNotFound() { $schema = (object) array( @@ -197,14 +197,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 +216,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#' ); @@ -235,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)) @@ -247,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)) @@ -257,19 +257,17 @@ public function testConfirmMediaTypeAcceptsJsonType() $this->assertEquals(null, $retriever->confirmMediaType($uriRetriever, null)); } - /** - * @expectedException \JsonSchema\Exception\InvalidSchemaMediaTypeException - */ 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'); - $this->assertEquals(null, $retriever->confirmMediaType($uriRetriever, null)); + $this->expectException(InvalidSchemaMediaTypeException::class); + + $retriever->confirmMediaType($uriRetriever, null); } private function mockRetriever($schema) @@ -302,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() @@ -335,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(); @@ -343,26 +341,26 @@ 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 = $this->createMock('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'); } 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'); - $retriever->confirmMediaType($mock, 'http://example.com'); + $result = $retriever->confirmMediaType($mock, 'http://example.com'); + + self::assertTrue($result); } public function testSchemaCache() @@ -388,10 +386,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); }