diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index f11ebd4e..3e4359bf 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -26,7 +26,8 @@ jobs: - "7.2" - "7.3" - "7.4" -# - "8.0" + - "8.0" + - "8.1" dependencies: [highest] experimental: [false] include: @@ -36,15 +37,12 @@ jobs: - 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: "8.0" + dependencies: highest + experimental: false + - php-version: "8.1" + dependencies: highest-ignore + experimental: true steps: - name: "Checkout" diff --git a/composer.json b/composer.json index f1b69142..147ff155 100644 --- a/composer.json +++ b/composer.json @@ -29,12 +29,14 @@ "require": { "php": ">=5.3.3", "marc-mabe/php-enum":"^2.0 || ^3.0 || ^4.0", - "icecave/parity": "1.0.0" + "icecave/parity": ">=1.0.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": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.29 || ^9.5.24", + "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1", + "phpspec/prophecy-phpunit": "^1.1 || ^2.0.1" }, "extra": { "branch-alias": { @@ -69,10 +71,10 @@ "bin/validate-json" ], "scripts": { - "coverage": "phpunit --coverage-text", + "coverage": "vendor/bin/phpunit --coverage-text", "style-check": "php-cs-fixer fix --dry-run --verbose --diff", "style-fix": "php-cs-fixer fix --verbose", - "test": "phpunit", - "testOnly": "phpunit --colors --filter" + "test": "vendor/bin/phpunit", + "testOnly": "vendor/bin/phpunit --colors --filter" } } diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index bd0082f0..b6b962f8 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -10,9 +10,9 @@ namespace JsonSchema\Tests; use JsonSchema\ConstraintError; -use PHPUnit\Framework\TestCase; +use JsonSchema\Tests\Constraints\VeryBaseTestCase; -class ConstraintErrorTest extends TestCase +class ConstraintErrorTest extends VeryBaseTestCase { public function testGetValidMessage() { @@ -24,7 +24,7 @@ public function testGetInvalidMessage() { $e = ConstraintError::MISSING_ERROR(); - $this->setExpectedException( + $this->expectExceptionCompat( '\JsonSchema\Exception\InvalidArgumentException', 'Missing error message for missingError' ); diff --git a/tests/Constraints/CoerciveTest.php b/tests/Constraints/CoerciveTest.php index 22684b3e..5b0557fe 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 doSetUp() { $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..a27efdcd 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -12,7 +12,6 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Constraints\Factory; use JsonSchema\Entity\JsonPointer; -use PHPUnit\Framework\TestCase; /** * Class MyBadConstraint @@ -35,14 +34,14 @@ public function check(&$value, $schema = null, JsonPointer $path = null, $i = nu } } -class FactoryTest extends TestCase +class FactoryTest extends VeryBaseTestCase { /** * @var Factory */ protected $factory; - protected function setUp() + protected function doSetUp() { $this->factory = new Factory(); } @@ -85,7 +84,7 @@ public function constraintNameProvider() */ public function testExceptionWhenCreateInstanceForInvalidConstraintName($constraintName) { - $this->setExpectedException('JsonSchema\Exception\InvalidArgumentException'); + $this->expectExceptionCompat('JsonSchema\Exception\InvalidArgumentException'); $this->factory->createInstanceFor($constraintName); } @@ -96,19 +95,17 @@ public function invalidConstraintNameProvider() ); } - /** - * @expectedException \JsonSchema\Exception\InvalidArgumentException - */ public function testSetConstraintClassExistsCondition() { + $this->expectExceptionCompat('\JsonSchema\Exception\InvalidArgumentException'); + $this->factory->setConstraintClass('string', 'SomeConstraint'); } - /** - * @expectedException \JsonSchema\Exception\InvalidArgumentException - */ public function testSetConstraintClassImplementsCondition() { + $this->expectExceptionCompat('\JsonSchema\Exception\InvalidArgumentException'); + $this->factory->setConstraintClass('string', 'JsonSchema\Tests\Constraints\MyBadConstraint'); } diff --git a/tests/Constraints/FormatTest.php b/tests/Constraints/FormatTest.php index 78706c33..a3602e47 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 doSetUp() { date_default_timezone_set('UTC'); } diff --git a/tests/Constraints/MinLengthMaxLengthMultiByteTest.php b/tests/Constraints/MinLengthMaxLengthMultiByteTest.php index b19ec4f7..530e12fd 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 doSetUp() { if (!extension_loaded('mbstring')) { $this->markTestSkipped('mbstring extension is not available'); diff --git a/tests/Constraints/PointerTest.php b/tests/Constraints/PointerTest.php index ef52e44b..6ae287db 100644 --- a/tests/Constraints/PointerTest.php +++ b/tests/Constraints/PointerTest.php @@ -10,7 +10,7 @@ namespace JsonSchema\Tests\Constraints; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class PointerTest extends TestCase { diff --git a/tests/Constraints/SchemaValidationTest.php b/tests/Constraints/SchemaValidationTest.php index 85907c5d..9ef05290 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -11,9 +11,8 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; -class SchemaValidationTest extends TestCase +class SchemaValidationTest extends VeryBaseTestCase { protected $validateSchema = true; @@ -102,7 +101,7 @@ public function testValidCases($schema) public function testNonObjectSchema() { - $this->setExpectedException( + $this->expectExceptionCompat( '\JsonSchema\Exception\RuntimeException', 'Cannot validate the schema of a non-object' ); @@ -111,7 +110,7 @@ public function testNonObjectSchema() public function testInvalidSchemaException() { - $this->setExpectedException( + $this->expectExceptionCompat( '\JsonSchema\Exception\InvalidSchemaException', 'Schema did not pass validation' ); diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index 70108eb6..5c5a2cc0 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->expectExceptionCompat('\JsonSchema\Exception\InvalidArgumentException'); $v->validate($value, $schema); } diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index a10996da..326fd736 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -11,7 +11,6 @@ use JsonSchema\Constraints\TypeCheck\LooseTypeCheck; use JsonSchema\Constraints\TypeConstraint; -use PHPUnit\Framework\TestCase; /** * Class TypeTest @@ -20,7 +19,7 @@ * * @author hakre */ -class TypeTest extends TestCase +class TypeTest extends VeryBaseTestCase { /** * @see testIndefiniteArticleForTypeInTypeCheckErrorMessage @@ -80,7 +79,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->assertIsArrayCompat($actualError, sprintf('Failed to assert that Type error is an array, %s given', gettype($actualError))); $messageKey = 'message'; $this->assertArrayHasKey( @@ -125,7 +124,7 @@ public function testInvalidateTypeNameWording() $m = $r->getMethod('validateTypeNameWording'); $m->setAccessible(true); - $this->setExpectedException( + $this->expectExceptionCompat( '\UnexpectedValueException', "No wording for 'notAValidTypeName' available, expected wordings are: [an integer, a number, a boolean, an object, an array, a string, a null]" ); @@ -138,7 +137,7 @@ public function testValidateTypeException() $data = new \stdClass(); $schema = json_decode('{"type": "notAValidTypeName"}'); - $this->setExpectedException( + $this->expectExceptionCompat( 'JsonSchema\Exception\InvalidArgumentException', 'object is an invalid type for notAValidTypeName' ); diff --git a/tests/Constraints/ValidationExceptionTest.php b/tests/Constraints/ValidationExceptionTest.php index 57995769..5a4085ef 100644 --- a/tests/Constraints/ValidationExceptionTest.php +++ b/tests/Constraints/ValidationExceptionTest.php @@ -12,9 +12,8 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Exception\ValidationException; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; -class ValidationExceptionTest extends TestCase +class ValidationExceptionTest extends VeryBaseTestCase { public function testValidationException() { @@ -45,7 +44,7 @@ public function testValidationException() $exception->getMessage() ); - $this->setExpectedException('JsonSchema\Exception\ValidationException'); + $this->expectExceptionCompat('JsonSchema\Exception\ValidationException'); throw $exception; } } diff --git a/tests/Constraints/VeryBaseTestCase.php b/tests/Constraints/VeryBaseTestCase.php index 7cd7c06b..71df3675 100644 --- a/tests/Constraints/VeryBaseTestCase.php +++ b/tests/Constraints/VeryBaseTestCase.php @@ -9,7 +9,7 @@ namespace JsonSchema\Tests\Constraints; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; use Prophecy\Argument; /** @@ -87,4 +87,22 @@ private function getJsonSchemaDraft04() return $this->jsonSchemaDraft04; } + + public function expectExceptionCompat($exception) + { + if (\is_callable(array('PHPUnit\Framework\TestCase', 'expectException'))) { + parent::expectException($exception); + } else { + $this->setExpectedException($exception); + } + } + + public static function assertIsArrayCompat($actual, $message = '') + { + if (\is_callable(array('PHPUnit\Framework\TestCase', 'assertIsArray'))) { + parent::assertIsArray($actual, $message); + } else { + static::assertInternalType('array', $actual, $message); + } + } } diff --git a/tests/Entity/JsonPointerTest.php b/tests/Entity/JsonPointerTest.php index d063d32d..a101a64e 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -10,14 +10,14 @@ namespace JsonSchema\Tests\Entity; use JsonSchema\Entity\JsonPointer; -use PHPUnit\Framework\TestCase; +use JsonSchema\Tests\Constraints\VeryBaseTestCase; /** * @package JsonSchema\Tests\Entity * * @author Joost Nijhuis */ -class JsonPointerTest extends TestCase +class JsonPointerTest extends VeryBaseTestCase { /** * @dataProvider getTestData @@ -113,7 +113,7 @@ public function testJsonPointerWithPropertyPaths() public function testCreateWithInvalidValue() { - $this->setExpectedException( + $this->expectExceptionCompat( '\JsonSchema\Exception\InvalidArgumentException', 'Ref value must be a string' ); diff --git a/tests/Exception/InvalidArgumentExceptionTest.php b/tests/Exception/InvalidArgumentExceptionTest.php index 5715fbac..d8c19a05 100644 --- a/tests/Exception/InvalidArgumentExceptionTest.php +++ b/tests/Exception/InvalidArgumentExceptionTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Exception; use JsonSchema\Exception\InvalidArgumentException; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class InvalidArgumentExceptionTest extends TestCase { diff --git a/tests/Exception/InvalidSchemaMediaTypeExceptionTest.php b/tests/Exception/InvalidSchemaMediaTypeExceptionTest.php index 6b12adc6..cd6a4f52 100644 --- a/tests/Exception/InvalidSchemaMediaTypeExceptionTest.php +++ b/tests/Exception/InvalidSchemaMediaTypeExceptionTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Exception; use JsonSchema\Exception\InvalidSchemaMediaTypeException; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class InvalidSchemaMediaTypeExceptionTest extends TestCase { diff --git a/tests/Exception/InvalidSourceUriExceptionTest.php b/tests/Exception/InvalidSourceUriExceptionTest.php index 7cccf817..57460c6f 100644 --- a/tests/Exception/InvalidSourceUriExceptionTest.php +++ b/tests/Exception/InvalidSourceUriExceptionTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Exception; use JsonSchema\Exception\InvalidSourceUriException; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class InvalidSourceUriExceptionTest extends TestCase { diff --git a/tests/Exception/JsonDecodingExceptionTest.php b/tests/Exception/JsonDecodingExceptionTest.php index 667c6520..d045222c 100644 --- a/tests/Exception/JsonDecodingExceptionTest.php +++ b/tests/Exception/JsonDecodingExceptionTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Exception; use JsonSchema\Exception\JsonDecodingException; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class JsonDecodingExceptionTest extends TestCase { diff --git a/tests/Exception/ResourceNotFoundExceptionTest.php b/tests/Exception/ResourceNotFoundExceptionTest.php index 2cde0eec..6938004a 100644 --- a/tests/Exception/ResourceNotFoundExceptionTest.php +++ b/tests/Exception/ResourceNotFoundExceptionTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Exception; use JsonSchema\Exception\ResourceNotFoundException; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class ResourceNotFoundExceptionTest extends TestCase { diff --git a/tests/Exception/RuntimeExceptionTest.php b/tests/Exception/RuntimeExceptionTest.php index 4db22eaa..fd4561d0 100644 --- a/tests/Exception/RuntimeExceptionTest.php +++ b/tests/Exception/RuntimeExceptionTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Exception; use JsonSchema\Exception\RuntimeException; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class RuntimeExceptionTest extends TestCase { diff --git a/tests/Exception/UnresolvableJsonPointerExceptionTest.php b/tests/Exception/UnresolvableJsonPointerExceptionTest.php index f061d9da..449b700f 100644 --- a/tests/Exception/UnresolvableJsonPointerExceptionTest.php +++ b/tests/Exception/UnresolvableJsonPointerExceptionTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Exception; use JsonSchema\Exception\UnresolvableJsonPointerException; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class UnresolvableJsonPointerExceptionTest extends TestCase { diff --git a/tests/Exception/UriResolverExceptionTest.php b/tests/Exception/UriResolverExceptionTest.php index eb9af83f..9a8a152b 100644 --- a/tests/Exception/UriResolverExceptionTest.php +++ b/tests/Exception/UriResolverExceptionTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Exception; use JsonSchema\Exception\UriResolverException; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class UriResolverExceptionTest extends TestCase { diff --git a/tests/Iterators/ObjectIteratorTest.php b/tests/Iterators/ObjectIteratorTest.php index e36d2ea4..a96a79a6 100644 --- a/tests/Iterators/ObjectIteratorTest.php +++ b/tests/Iterators/ObjectIteratorTest.php @@ -10,13 +10,13 @@ namespace JsonSchema\Tests\Iterators; use JsonSchema\Iterator\ObjectIterator; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class ObjectIteratorTest extends TestCase { protected $testObject; - public function setUp() + public function doSetUp() { $this->testObject = (object) array( 'subOne' => (object) array( diff --git a/tests/RefTest.php b/tests/RefTest.php index 64525122..27d22aa5 100644 --- a/tests/RefTest.php +++ b/tests/RefTest.php @@ -9,10 +9,10 @@ namespace JsonSchema\Tests; +use JsonSchema\Tests\Constraints\VeryBaseTestCase; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; -class RefTest extends TestCase +class RefTest extends VeryBaseTestCase { public function dataRefIgnoresSiblings() { @@ -69,7 +69,7 @@ public function testRefIgnoresSiblings($schema, $document, $isValid, $exception $v = new Validator(); if ($exception) { - $this->setExpectedException($exception); + $this->expectExceptionCompat($exception); } $v->validate($document, $schema); diff --git a/tests/Rfc3339Test.php b/tests/Rfc3339Test.php index e489d389..7e975958 100644 --- a/tests/Rfc3339Test.php +++ b/tests/Rfc3339Test.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests; use JsonSchema\Rfc3339; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class Rfc3339Test extends TestCase { diff --git a/tests/SchemaStorageTest.php b/tests/SchemaStorageTest.php index ebbc9477..2e43e233 100644 --- a/tests/SchemaStorageTest.php +++ b/tests/SchemaStorageTest.php @@ -10,11 +10,11 @@ namespace JsonSchema\Tests; use JsonSchema\SchemaStorage; +use JsonSchema\Tests\Constraints\VeryBaseTestCase; use JsonSchema\Uri\UriRetriever; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; -class SchemaStorageTest extends TestCase +class SchemaStorageTest extends VeryBaseTestCase { public function testResolveRef() { @@ -102,7 +102,7 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference() public function testUnresolvableJsonPointExceptionShouldBeThrown() { - $this->setExpectedException( + $this->expectExceptionCompat( 'JsonSchema\Exception\UnresolvableJsonPointerException', 'File: http://www.example.com/schema.json is found, but could not resolve fragment: #/definitions/car' ); @@ -121,7 +121,7 @@ public function testUnresolvableJsonPointExceptionShouldBeThrown() public function testResolveRefWithNoAssociatedFileName() { - $this->setExpectedException( + $this->expectExceptionCompat( 'JsonSchema\Exception\UnresolvableJsonPointerException', "Could not resolve fragment '#': no file is defined" ); diff --git a/tests/Uri/Retrievers/CurlTest.php b/tests/Uri/Retrievers/CurlTest.php index 550baff1..95b36c03 100644 --- a/tests/Uri/Retrievers/CurlTest.php +++ b/tests/Uri/Retrievers/CurlTest.php @@ -2,10 +2,10 @@ namespace JsonSchema\Tests\Uri\Retrievers { + use JsonSchema\Tests\Constraints\VeryBaseTestCase; use JsonSchema\Uri\Retrievers\Curl; - use PHPUnit\Framework\TestCase; - class CurlTest extends TestCase + class CurlTest extends VeryBaseTestCase { public function testRetrieveFile() { @@ -17,7 +17,7 @@ public function testRetrieveNonexistantFile() { $c = new Curl(); - $this->setExpectedException( + $this->expectExceptionCompat( '\JsonSchema\Exception\ResourceNotFoundException', 'JSON schema not found' ); diff --git a/tests/Uri/Retrievers/FileGetContentsTest.php b/tests/Uri/Retrievers/FileGetContentsTest.php index 0514a7d5..a80b08d2 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -2,20 +2,19 @@ namespace JsonSchema\Tests\Uri\Retrievers { - use JsonSchema\Uri\Retrievers\FileGetContents; - use PHPUnit\Framework\TestCase; + use JsonSchema\Tests\Constraints\VeryBaseTestCase; +use JsonSchema\Uri\Retrievers\FileGetContents; /** * @group FileGetContents */ - class FileGetContentsTest extends TestCase + class FileGetContentsTest extends VeryBaseTestCase { - /** - * @expectedException \JsonSchema\Exception\ResourceNotFoundException - */ public function testFetchMissingFile() { $res = new FileGetContents(); + + $this->expectExceptionCompat('\JsonSchema\Exception\ResourceNotFoundException'); $res->retrieve(__DIR__ . '/Fixture/missing.json'); } @@ -30,7 +29,7 @@ public function testFalseReturn() { $res = new FileGetContents(); - $this->setExpectedException( + $this->expectExceptionCompat( '\JsonSchema\Exception\ResourceNotFoundException', 'JSON schema not found at http://example.com/false' ); @@ -41,7 +40,7 @@ public function testFetchDirectory() { $res = new FileGetContents(); - $this->setExpectedException( + $this->expectExceptionCompat( '\JsonSchema\Exception\ResourceNotFoundException', 'JSON schema not found at file:///this/is/a/directory/' ); diff --git a/tests/Uri/Retrievers/PredefinedArrayTest.php b/tests/Uri/Retrievers/PredefinedArrayTest.php index 7684bb1f..25006d24 100644 --- a/tests/Uri/Retrievers/PredefinedArrayTest.php +++ b/tests/Uri/Retrievers/PredefinedArrayTest.php @@ -2,17 +2,17 @@ namespace JsonSchema\Tests\Uri\Retrievers; +use JsonSchema\Tests\Constraints\VeryBaseTestCase; use JsonSchema\Uri\Retrievers\PredefinedArray; -use PHPUnit\Framework\TestCase; /** * @group PredefinedArray */ -class PredefinedArrayTest extends TestCase +class PredefinedArrayTest extends VeryBaseTestCase { private $retriever; - public function setUp() + public function doSetUp() { $this->retriever = new PredefinedArray( array( @@ -29,11 +29,10 @@ public function testRetrieve() $this->assertEquals('THE_ADDRESS_SCHEMA', $this->retriever->retrieve('http://acme.com/schemas/address#')); } - /** - * @expectedException \JsonSchema\Exception\ResourceNotFoundException - */ public function testRetrieveNonExistsingSchema() { + $this->expectExceptionCompat('\JsonSchema\Exception\ResourceNotFoundException'); + $this->retriever->retrieve('http://acme.com/schemas/plop#'); } diff --git a/tests/Uri/UriResolverTest.php b/tests/Uri/UriResolverTest.php index a353de50..652b8c60 100644 --- a/tests/Uri/UriResolverTest.php +++ b/tests/Uri/UriResolverTest.php @@ -2,12 +2,12 @@ namespace JsonSchema\Tests\Uri; +use JsonSchema\Tests\Constraints\VeryBaseTestCase; use JsonSchema\Uri\UriResolver; -use PHPUnit\Framework\TestCase; -class UriResolverTest extends TestCase +class UriResolverTest extends VeryBaseTestCase { - public function setUp() + public function doSetUp() { $this->resolver = new UriResolver(); } @@ -94,11 +94,10 @@ public function testResolveAbsoluteUri() ); } - /** - * @expectedException \JsonSchema\Exception\UriResolverException - */ public function testResolveRelativeUriNoBase() { + $this->expectExceptionCompat('\JsonSchema\Exception\UriResolverException'); + $this->assertEquals( 'http://example.org/foo/bar.json', $this->resolver->resolve( diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 24714a26..1b842cff 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -10,18 +10,18 @@ namespace JsonSchema\Tests\Uri; use JsonSchema\Exception\JsonDecodingException; +use JsonSchema\Tests\Constraints\VeryBaseTestCase; use JsonSchema\Uri\UriRetriever; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; /** * @group UriRetriever */ -class UriRetrieverTest extends TestCase +class UriRetrieverTest extends VeryBaseTestCase { protected $validator; - protected function setUp() + protected function doSetUp() { $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->getMockCompat('JsonSchema\Uri\UriRetriever', array('retrieve')); $retriever->expects($this->at(0)) ->method('retrieve') @@ -182,9 +182,6 @@ public function testResolvePointerFragment() ); } - /** - * @expectedException \JsonSchema\Exception\ResourceNotFoundException - */ public function testResolvePointerFragmentNotFound() { $schema = (object) array( @@ -197,14 +194,12 @@ public function testResolvePointerFragmentNotFound() ); $retriever = new \JsonSchema\Uri\UriRetriever(); + $this->expectExceptionCompat('\JsonSchema\Exception\ResourceNotFoundException'); $retriever->resolvePointer( $schema, 'http://example.org/schema.json#/definitions/bar' ); } - /** - * @expectedException \JsonSchema\Exception\ResourceNotFoundException - */ public function testResolvePointerFragmentNoArray() { $schema = (object) array( @@ -217,17 +212,16 @@ public function testResolvePointerFragmentNoArray() ); $retriever = new \JsonSchema\Uri\UriRetriever(); + $this->expectExceptionCompat('\JsonSchema\Exception\ResourceNotFoundException'); $retriever->resolvePointer( $schema, 'http://example.org/schema.json#/definitions/foo' ); } - /** - * @expectedException \JsonSchema\Exception\UriResolverException - */ public function testResolveExcessLevelUp() { $retriever = new \JsonSchema\Uri\UriRetriever(); + $this->expectExceptionCompat('\JsonSchema\Exception\UriResolverException'); $retriever->resolve( '../schema.json#', 'http://example.org/schema.json#' ); @@ -235,7 +229,7 @@ public function testResolveExcessLevelUp() public function testConfirmMediaTypeAcceptsJsonSchemaType() { - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retriever = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('getContentType')); $retriever->expects($this->at(0)) ->method('getContentType') @@ -246,7 +240,7 @@ public function testConfirmMediaTypeAcceptsJsonSchemaType() public function testConfirmMediaTypeAcceptsJsonType() { - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retriever = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('getContentType')); $retriever->expects($this->at(0)) ->method('getContentType') @@ -255,17 +249,15 @@ public function testConfirmMediaTypeAcceptsJsonType() $this->assertEquals(null, $retriever->confirmMediaType($retriever, null)); } - /** - * @expectedException \JsonSchema\Exception\InvalidSchemaMediaTypeException - */ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() { - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retriever = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('getContentType')); $retriever->expects($this->at(0)) ->method('getContentType') ->will($this->returnValue('text/html')); + $this->expectExceptionCompat('\JsonSchema\Exception\InvalidSchemaMediaTypeException'); $this->assertEquals(null, $retriever->confirmMediaType($retriever, null)); } @@ -332,7 +324,7 @@ public function testRetrieveSchemaFromPackage() public function testInvalidContentTypeEndpointsDefault() { - $mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -340,21 +332,19 @@ public function testInvalidContentTypeEndpointsDefault() $this->assertTrue($retriever->confirmMediaType($mock, 'https://json-schema.org/')); } - /** - * @expectedException \JsonSchema\Exception\InvalidSchemaMediaTypeException - */ public function testInvalidContentTypeEndpointsUnknown() { - $mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); + $this->expectExceptionCompat('\JsonSchema\Exception\InvalidSchemaMediaTypeException'); $retriever->confirmMediaType($mock, 'http://example.com'); } public function testInvalidContentTypeEndpointsAdded() { - $mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); $retriever->addInvalidContentTypeEndpoint('http://example.com'); @@ -385,7 +375,7 @@ public function testLoadSchemaJSONDecodingException() { $retriever = new UriRetriever(); - $this->setExpectedException( + $this->expectExceptionCompat( 'JsonSchema\Exception\JsonDecodingException', 'JSON syntax is malformed' ); @@ -436,4 +426,13 @@ public function testIsValidURI() $retriever = new UriRetriever(); $this->assertTrue($retriever->isValid('http://example.com/schema')); } + + private function getMockCompat($originalClassName, $methods) + { + if (\is_callable(array('PHPUnit\Framework\TestCase', 'createPartialMock'))) { + return $this->createPartialMock($originalClassName, $methods); + } + + return parent::getMock($originalClassName, $methods); + } } diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index ca62e45c..c340d24f 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -2,10 +2,10 @@ namespace JsonSchema\Tests; +use JsonSchema\Tests\Constraints\VeryBaseTestCase; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; -class ValidatorTest extends TestCase +class ValidatorTest extends VeryBaseTestCase { public function testValidateWithAssocSchema() { @@ -31,7 +31,7 @@ public function testBadAssocSchemaInput() $validator = new Validator(); - $this->setExpectedException('\JsonSchema\Exception\InvalidArgumentException'); + $this->expectExceptionCompat('\JsonSchema\Exception\InvalidArgumentException'); $validator->validate($data, $schema); }