From ff33d72d22dd407505fae4e57e4a3c2557bb12db Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 31 Aug 2022 20:28:02 +0900 Subject: [PATCH 01/29] Another attempt to make it work under PHP 5.3 and PHP 8+ --- .github/workflows/continuous-integration.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index f11ebd4e..7716a088 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -26,7 +26,7 @@ jobs: - "7.2" - "7.3" - "7.4" -# - "8.0" + - "8.0" dependencies: [highest] experimental: [false] include: @@ -36,15 +36,15 @@ 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: lowest-ignore + experimental: true + - php-version: "8.1" + dependencies: highest-ignore + experimental: true steps: - name: "Checkout" From ac97290290e1875fe8335c1d3d5c7605b7f0b96f Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 31 Aug 2022 20:32:21 +0900 Subject: [PATCH 02/29] Use adapter instead --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f1b69142..ae92f13f 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" + "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1" }, "extra": { "branch-alias": { From cc3d1cb5a27e175a9b702c1fd9452105d2995b89 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 31 Aug 2022 20:34:11 +0900 Subject: [PATCH 03/29] Use a different TestCase implementation git grep --name-only PHPUnit.Framework.TestCase | xargs sed -i 's:PHPUnit.Framework.TestCase:LegacyPHPUnit\\TestCase:g' --- tests/ConstraintErrorTest.php | 2 +- tests/Constraints/FactoryTest.php | 2 +- tests/Constraints/PointerTest.php | 2 +- tests/Constraints/SchemaValidationTest.php | 2 +- tests/Constraints/TypeTest.php | 2 +- tests/Constraints/ValidationExceptionTest.php | 2 +- tests/Constraints/VeryBaseTestCase.php | 2 +- tests/Entity/JsonPointerTest.php | 2 +- tests/Exception/InvalidArgumentExceptionTest.php | 2 +- tests/Exception/InvalidSchemaMediaTypeExceptionTest.php | 2 +- tests/Exception/InvalidSourceUriExceptionTest.php | 2 +- tests/Exception/JsonDecodingExceptionTest.php | 2 +- tests/Exception/ResourceNotFoundExceptionTest.php | 2 +- tests/Exception/RuntimeExceptionTest.php | 2 +- tests/Exception/UnresolvableJsonPointerExceptionTest.php | 2 +- tests/Exception/UriResolverExceptionTest.php | 2 +- tests/Iterators/ObjectIteratorTest.php | 2 +- tests/RefTest.php | 2 +- tests/Rfc3339Test.php | 2 +- tests/SchemaStorageTest.php | 2 +- tests/Uri/Retrievers/CurlTest.php | 2 +- tests/Uri/Retrievers/FileGetContentsTest.php | 2 +- tests/Uri/Retrievers/PredefinedArrayTest.php | 2 +- tests/Uri/UriResolverTest.php | 2 +- tests/Uri/UriRetrieverTest.php | 2 +- tests/ValidatorTest.php | 2 +- 26 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index bd0082f0..181f7133 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -10,7 +10,7 @@ namespace JsonSchema\Tests; use JsonSchema\ConstraintError; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class ConstraintErrorTest extends TestCase { diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index adc11844..2d397125 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -12,7 +12,7 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Constraints\Factory; use JsonSchema\Entity\JsonPointer; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; /** * Class MyBadConstraint 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..7bc862d3 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -11,7 +11,7 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class SchemaValidationTest extends TestCase { diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index a10996da..31a6d176 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -11,7 +11,7 @@ use JsonSchema\Constraints\TypeCheck\LooseTypeCheck; use JsonSchema\Constraints\TypeConstraint; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; /** * Class TypeTest diff --git a/tests/Constraints/ValidationExceptionTest.php b/tests/Constraints/ValidationExceptionTest.php index 57995769..47a8c375 100644 --- a/tests/Constraints/ValidationExceptionTest.php +++ b/tests/Constraints/ValidationExceptionTest.php @@ -12,7 +12,7 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Exception\ValidationException; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class ValidationExceptionTest extends TestCase { diff --git a/tests/Constraints/VeryBaseTestCase.php b/tests/Constraints/VeryBaseTestCase.php index 7cd7c06b..3b5c4cdb 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; /** diff --git a/tests/Entity/JsonPointerTest.php b/tests/Entity/JsonPointerTest.php index d063d32d..09239bbb 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -10,7 +10,7 @@ namespace JsonSchema\Tests\Entity; use JsonSchema\Entity\JsonPointer; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; /** * @package JsonSchema\Tests\Entity 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..1044cd4d 100644 --- a/tests/Iterators/ObjectIteratorTest.php +++ b/tests/Iterators/ObjectIteratorTest.php @@ -10,7 +10,7 @@ namespace JsonSchema\Tests\Iterators; use JsonSchema\Iterator\ObjectIterator; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class ObjectIteratorTest extends TestCase { diff --git a/tests/RefTest.php b/tests/RefTest.php index 64525122..33b34a5a 100644 --- a/tests/RefTest.php +++ b/tests/RefTest.php @@ -10,7 +10,7 @@ namespace JsonSchema\Tests; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class RefTest extends TestCase { 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..c38dff0a 100644 --- a/tests/SchemaStorageTest.php +++ b/tests/SchemaStorageTest.php @@ -12,7 +12,7 @@ use JsonSchema\SchemaStorage; use JsonSchema\Uri\UriRetriever; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class SchemaStorageTest extends TestCase { diff --git a/tests/Uri/Retrievers/CurlTest.php b/tests/Uri/Retrievers/CurlTest.php index 550baff1..955ca2c0 100644 --- a/tests/Uri/Retrievers/CurlTest.php +++ b/tests/Uri/Retrievers/CurlTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Uri\Retrievers { use JsonSchema\Uri\Retrievers\Curl; - use PHPUnit\Framework\TestCase; + use LegacyPHPUnit\TestCase; class CurlTest extends TestCase { diff --git a/tests/Uri/Retrievers/FileGetContentsTest.php b/tests/Uri/Retrievers/FileGetContentsTest.php index 0514a7d5..dd4cb494 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Uri\Retrievers { use JsonSchema\Uri\Retrievers\FileGetContents; - use PHPUnit\Framework\TestCase; + use LegacyPHPUnit\TestCase; /** * @group FileGetContents diff --git a/tests/Uri/Retrievers/PredefinedArrayTest.php b/tests/Uri/Retrievers/PredefinedArrayTest.php index 7684bb1f..e8ea287f 100644 --- a/tests/Uri/Retrievers/PredefinedArrayTest.php +++ b/tests/Uri/Retrievers/PredefinedArrayTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Uri\Retrievers; use JsonSchema\Uri\Retrievers\PredefinedArray; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; /** * @group PredefinedArray diff --git a/tests/Uri/UriResolverTest.php b/tests/Uri/UriResolverTest.php index a353de50..fce068f7 100644 --- a/tests/Uri/UriResolverTest.php +++ b/tests/Uri/UriResolverTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests\Uri; use JsonSchema\Uri\UriResolver; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class UriResolverTest extends TestCase { diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 24714a26..5f4256ad 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -12,7 +12,7 @@ use JsonSchema\Exception\JsonDecodingException; use JsonSchema\Uri\UriRetriever; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; /** * @group UriRetriever diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index ca62e45c..41571a0f 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -3,7 +3,7 @@ namespace JsonSchema\Tests; use JsonSchema\Validator; -use PHPUnit\Framework\TestCase; +use LegacyPHPUnit\TestCase; class ValidatorTest extends TestCase { From 861deeca7e46958cd77ba5a5cff8b8eb3c810285 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 31 Aug 2022 20:44:02 +0900 Subject: [PATCH 04/29] Renames, dependencies --- composer.json | 5 +++-- tests/ConstraintErrorTest.php | 2 +- tests/Constraints/CoerciveTest.php | 2 +- tests/Constraints/FactoryTest.php | 4 ++-- tests/Constraints/FormatTest.php | 2 +- tests/Constraints/MinLengthMaxLengthMultiByteTest.php | 2 +- tests/Constraints/SchemaValidationTest.php | 4 ++-- tests/Constraints/SelfDefinedSchemaTest.php | 2 +- tests/Constraints/TypeTest.php | 4 ++-- tests/Constraints/ValidationExceptionTest.php | 2 +- tests/Entity/JsonPointerTest.php | 2 +- tests/Iterators/ObjectIteratorTest.php | 2 +- tests/RefTest.php | 2 +- tests/SchemaStorageTest.php | 4 ++-- tests/Uri/Retrievers/CurlTest.php | 2 +- tests/Uri/Retrievers/FileGetContentsTest.php | 4 ++-- tests/Uri/Retrievers/PredefinedArrayTest.php | 2 +- tests/Uri/UriResolverTest.php | 2 +- tests/Uri/UriRetrieverTest.php | 4 ++-- tests/ValidatorTest.php | 2 +- 20 files changed, 28 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index ae92f13f..c1933ba3 100644 --- a/composer.json +++ b/composer.json @@ -29,12 +29,13 @@ "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", - "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1" + "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1", + "phpspec/prophecy": "^1.15" }, "extra": { "branch-alias": { diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index 181f7133..52a3e8b0 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -24,7 +24,7 @@ public function testGetInvalidMessage() { $e = ConstraintError::MISSING_ERROR(); - $this->setExpectedException( + $this->expectException( '\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 2d397125..1d56de73 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 doSetUp() { $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..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/SchemaValidationTest.php b/tests/Constraints/SchemaValidationTest.php index 7bc862d3..0330bb3d 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -102,7 +102,7 @@ public function testValidCases($schema) public function testNonObjectSchema() { - $this->setExpectedException( + $this->expectException( '\JsonSchema\Exception\RuntimeException', 'Cannot validate the schema of a non-object' ); @@ -111,7 +111,7 @@ public function testNonObjectSchema() public function testInvalidSchemaException() { - $this->setExpectedException( + $this->expectException( '\JsonSchema\Exception\InvalidSchemaException', 'Schema did not pass validation' ); 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 31a6d176..86f68408 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -125,7 +125,7 @@ public function testInvalidateTypeNameWording() $m = $r->getMethod('validateTypeNameWording'); $m->setAccessible(true); - $this->setExpectedException( + $this->expectException( '\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 +138,7 @@ public function testValidateTypeException() $data = new \stdClass(); $schema = json_decode('{"type": "notAValidTypeName"}'); - $this->setExpectedException( + $this->expectException( 'JsonSchema\Exception\InvalidArgumentException', 'object is an invalid type for notAValidTypeName' ); diff --git a/tests/Constraints/ValidationExceptionTest.php b/tests/Constraints/ValidationExceptionTest.php index 47a8c375..1c928d1f 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 09239bbb..413c3ddd 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -113,7 +113,7 @@ public function testJsonPointerWithPropertyPaths() public function testCreateWithInvalidValue() { - $this->setExpectedException( + $this->expectException( '\JsonSchema\Exception\InvalidArgumentException', 'Ref value must be a string' ); diff --git a/tests/Iterators/ObjectIteratorTest.php b/tests/Iterators/ObjectIteratorTest.php index 1044cd4d..a96a79a6 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 doSetUp() { $this->testObject = (object) array( 'subOne' => (object) array( diff --git a/tests/RefTest.php b/tests/RefTest.php index 33b34a5a..153b32e9 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 c38dff0a..49da3c50 100644 --- a/tests/SchemaStorageTest.php +++ b/tests/SchemaStorageTest.php @@ -102,7 +102,7 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference() public function testUnresolvableJsonPointExceptionShouldBeThrown() { - $this->setExpectedException( + $this->expectException( '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->expectException( '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 955ca2c0..00417164 100644 --- a/tests/Uri/Retrievers/CurlTest.php +++ b/tests/Uri/Retrievers/CurlTest.php @@ -17,7 +17,7 @@ public function testRetrieveNonexistantFile() { $c = new Curl(); - $this->setExpectedException( + $this->expectException( '\JsonSchema\Exception\ResourceNotFoundException', 'JSON schema not found' ); diff --git a/tests/Uri/Retrievers/FileGetContentsTest.php b/tests/Uri/Retrievers/FileGetContentsTest.php index dd4cb494..e790b6a7 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -30,7 +30,7 @@ public function testFalseReturn() { $res = new FileGetContents(); - $this->setExpectedException( + $this->expectException( '\JsonSchema\Exception\ResourceNotFoundException', 'JSON schema not found at http://example.com/false' ); @@ -41,7 +41,7 @@ public function testFetchDirectory() { $res = new FileGetContents(); - $this->setExpectedException( + $this->expectException( '\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 e8ea287f..1772adf6 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 doSetUp() { $this->retriever = new PredefinedArray( array( diff --git a/tests/Uri/UriResolverTest.php b/tests/Uri/UriResolverTest.php index fce068f7..c464b140 100644 --- a/tests/Uri/UriResolverTest.php +++ b/tests/Uri/UriResolverTest.php @@ -7,7 +7,7 @@ class UriResolverTest extends TestCase { - public function setUp() + public function doSetUp() { $this->resolver = new UriResolver(); } diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 5f4256ad..9fbfa68b 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 doSetUp() { $this->validator = new Validator(); } @@ -385,7 +385,7 @@ public function testLoadSchemaJSONDecodingException() { $retriever = new UriRetriever(); - $this->setExpectedException( + $this->expectException( 'JsonSchema\Exception\JsonDecodingException', 'JSON syntax is malformed' ); diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index 41571a0f..3ad64492 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 5bb24e37ce7077caa04715c64886f501328c1455 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 31 Aug 2022 20:49:00 +0900 Subject: [PATCH 05/29] /getMock/createPartialMock/ --- tests/Uri/UriRetrieverTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 9fbfa68b..cb731763 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -34,7 +34,7 @@ private function getRetrieverMock($returnSchema) throw new JsonDecodingException($error); } - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('retrieve')); + $retriever = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('retrieve')); $retriever->expects($this->at(0)) ->method('retrieve') @@ -235,7 +235,7 @@ public function testResolveExcessLevelUp() public function testConfirmMediaTypeAcceptsJsonSchemaType() { - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retriever = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); $retriever->expects($this->at(0)) ->method('getContentType') @@ -246,7 +246,7 @@ public function testConfirmMediaTypeAcceptsJsonSchemaType() public function testConfirmMediaTypeAcceptsJsonType() { - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retriever = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); $retriever->expects($this->at(0)) ->method('getContentType') @@ -260,7 +260,7 @@ public function testConfirmMediaTypeAcceptsJsonType() */ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() { - $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retriever = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); $retriever->expects($this->at(0)) ->method('getContentType') @@ -332,7 +332,7 @@ public function testRetrieveSchemaFromPackage() public function testInvalidContentTypeEndpointsDefault() { - $mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -345,7 +345,7 @@ public function testInvalidContentTypeEndpointsDefault() */ public function testInvalidContentTypeEndpointsUnknown() { - $mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -354,7 +354,7 @@ public function testInvalidContentTypeEndpointsUnknown() public function testInvalidContentTypeEndpointsAdded() { - $mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); $retriever->addInvalidContentTypeEndpoint('http://example.com'); From 80bb70e73ea06e9251c5d3f32efcc3b59c7fa9d3 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 31 Aug 2022 20:51:31 +0900 Subject: [PATCH 06/29] expectException instead --- tests/Uri/UriRetrieverTest.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index cb731763..47c3de49 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,12 @@ public function testResolvePointerFragmentNotFound() ); $retriever = new \JsonSchema\Uri\UriRetriever(); + $this->expectException('\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->expectException('\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->expectException('\JsonSchema\Exception\UriResolverException'); $retriever->resolve( '../schema.json#', 'http://example.org/schema.json#' ); @@ -266,6 +260,7 @@ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() ->method('getContentType') ->will($this->returnValue('text/html')); + $this->expectException('\JsonSchema\Exception\InvalidSchemaMediaTypeException'); $this->assertEquals(null, $retriever->confirmMediaType($retriever, null)); } @@ -340,15 +335,13 @@ public function testInvalidContentTypeEndpointsDefault() $this->assertTrue($retriever->confirmMediaType($mock, 'https://json-schema.org/')); } - /** - * @expectedException \JsonSchema\Exception\InvalidSchemaMediaTypeException - */ public function testInvalidContentTypeEndpointsUnknown() { $mock = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); + $this->expectException('\JsonSchema\Exception\InvalidSchemaMediaTypeException'); $retriever->confirmMediaType($mock, 'http://example.com'); } From 43c49e77a0412ec4bf6d7bbddb5a1261f86b7fef Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:00:18 +0900 Subject: [PATCH 07/29] Fix more tests PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer fix -v --rules=@PHPUnit48Migration:risky --allow-risky=yes --- tests/Constraints/FactoryTest.php | 10 ++++------ tests/Uri/Retrievers/FileGetContentsTest.php | 5 ++--- tests/Uri/Retrievers/PredefinedArrayTest.php | 5 ++--- tests/Uri/UriResolverTest.php | 5 ++--- tests/Uri/UriRetrieverTest.php | 5 ++--- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index 1d56de73..f4e06e04 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->setExpectedException(\JsonSchema\Exception\InvalidArgumentException::class); + $this->factory->setConstraintClass('string', 'SomeConstraint'); } - /** - * @expectedException \JsonSchema\Exception\InvalidArgumentException - */ public function testSetConstraintClassImplementsCondition() { + $this->setExpectedException(\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 e790b6a7..8949d9ef 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -10,11 +10,10 @@ */ class FileGetContentsTest extends TestCase { - /** - * @expectedException \JsonSchema\Exception\ResourceNotFoundException - */ public function testFetchMissingFile() { + $this->setExpectedException(\JsonSchema\Exception\ResourceNotFoundException::class); + $res = new FileGetContents(); $res->retrieve(__DIR__ . '/Fixture/missing.json'); } diff --git a/tests/Uri/Retrievers/PredefinedArrayTest.php b/tests/Uri/Retrievers/PredefinedArrayTest.php index 1772adf6..fc858dcb 100644 --- a/tests/Uri/Retrievers/PredefinedArrayTest.php +++ b/tests/Uri/Retrievers/PredefinedArrayTest.php @@ -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->setExpectedException(\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 c464b140..e23ab893 100644 --- a/tests/Uri/UriResolverTest.php +++ b/tests/Uri/UriResolverTest.php @@ -94,11 +94,10 @@ public function testResolveAbsoluteUri() ); } - /** - * @expectedException \JsonSchema\Exception\UriResolverException - */ public function testResolveRelativeUriNoBase() { + $this->setExpectedException(\JsonSchema\Exception\UriResolverException::class); + $this->assertEquals( 'http://example.org/foo/bar.json', $this->resolver->resolve( diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 47c3de49..f3e2a3d3 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -249,11 +249,10 @@ public function testConfirmMediaTypeAcceptsJsonType() $this->assertEquals(null, $retriever->confirmMediaType($retriever, null)); } - /** - * @expectedException \JsonSchema\Exception\InvalidSchemaMediaTypeException - */ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() { + $this->setExpectedException(\JsonSchema\Exception\InvalidSchemaMediaTypeException::class); + $retriever = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); $retriever->expects($this->at(0)) From 6530d3fe52057cadb71368821c834ce5329d18e8 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:06:20 +0900 Subject: [PATCH 08/29] Fix remaining errors --- tests/Constraints/FactoryTest.php | 4 ++-- tests/Constraints/TypeTest.php | 2 +- tests/Uri/Retrievers/FileGetContentsTest.php | 4 ++-- tests/Uri/Retrievers/PredefinedArrayTest.php | 2 +- tests/Uri/UriResolverTest.php | 2 +- tests/Uri/UriRetrieverTest.php | 2 -- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index f4e06e04..e386e6f5 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -98,14 +98,14 @@ public function invalidConstraintNameProvider() public function testSetConstraintClassExistsCondition() { - $this->setExpectedException(\JsonSchema\Exception\InvalidArgumentException::class); + $this->expectException(\JsonSchema\Exception\InvalidArgumentException::class); $this->factory->setConstraintClass('string', 'SomeConstraint'); } public function testSetConstraintClassImplementsCondition() { - $this->setExpectedException(\JsonSchema\Exception\InvalidArgumentException::class); + $this->expectException(\JsonSchema\Exception\InvalidArgumentException::class); $this->factory->setConstraintClass('string', 'JsonSchema\Tests\Constraints\MyBadConstraint'); } diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index 86f68408..9256e533 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( diff --git a/tests/Uri/Retrievers/FileGetContentsTest.php b/tests/Uri/Retrievers/FileGetContentsTest.php index 8949d9ef..33a44864 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -12,9 +12,9 @@ class FileGetContentsTest extends TestCase { public function testFetchMissingFile() { - $this->setExpectedException(\JsonSchema\Exception\ResourceNotFoundException::class); - $res = new FileGetContents(); + + $this->expectException('\JsonSchema\Exception\ResourceNotFoundException'); $res->retrieve(__DIR__ . '/Fixture/missing.json'); } diff --git a/tests/Uri/Retrievers/PredefinedArrayTest.php b/tests/Uri/Retrievers/PredefinedArrayTest.php index fc858dcb..f0538161 100644 --- a/tests/Uri/Retrievers/PredefinedArrayTest.php +++ b/tests/Uri/Retrievers/PredefinedArrayTest.php @@ -31,7 +31,7 @@ public function testRetrieve() public function testRetrieveNonExistsingSchema() { - $this->setExpectedException(\JsonSchema\Exception\ResourceNotFoundException::class); + $this->expectException('\JsonSchema\Exception\ResourceNotFoundException'); $this->retriever->retrieve('http://acme.com/schemas/plop#'); } diff --git a/tests/Uri/UriResolverTest.php b/tests/Uri/UriResolverTest.php index e23ab893..47df3df3 100644 --- a/tests/Uri/UriResolverTest.php +++ b/tests/Uri/UriResolverTest.php @@ -96,7 +96,7 @@ public function testResolveAbsoluteUri() public function testResolveRelativeUriNoBase() { - $this->setExpectedException(\JsonSchema\Exception\UriResolverException::class); + $this->expectException('\JsonSchema\Exception\UriResolverException'); $this->assertEquals( 'http://example.org/foo/bar.json', diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index f3e2a3d3..be55ce30 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -251,8 +251,6 @@ public function testConfirmMediaTypeAcceptsJsonType() public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() { - $this->setExpectedException(\JsonSchema\Exception\InvalidSchemaMediaTypeException::class); - $retriever = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); $retriever->expects($this->at(0)) From ebc12431eb8e03ea656e79bc473991bc4d551945 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:08:21 +0900 Subject: [PATCH 09/29] Require PHPUnit <10 --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index c1933ba3..da73bc46 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +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 <10", "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1", "phpspec/prophecy": "^1.15" }, From df084601161716f1401d065f9ffdc97064f99d24 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:11:10 +0900 Subject: [PATCH 10/29] Swap dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index da73bc46..88d25730 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "json-schema/json-schema-test-suite": "1.2.0", "phpunit/phpunit": ">=4.8.35 <10", "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1", - "phpspec/prophecy": "^1.15" + "phpspec/prophecy-phpunit": ">=1.0" }, "extra": { "branch-alias": { From 9fc46716a1668a185307aaeb682d3909d050008d Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:13:28 +0900 Subject: [PATCH 11/29] PHP 5.3 fix --- tests/Constraints/FactoryTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index e386e6f5..a8c4f038 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -98,14 +98,14 @@ public function invalidConstraintNameProvider() public function testSetConstraintClassExistsCondition() { - $this->expectException(\JsonSchema\Exception\InvalidArgumentException::class); + $this->expectException('\JsonSchema\Exception\InvalidArgumentException'); $this->factory->setConstraintClass('string', 'SomeConstraint'); } public function testSetConstraintClassImplementsCondition() { - $this->expectException(\JsonSchema\Exception\InvalidArgumentException::class); + $this->expectException('\JsonSchema\Exception\InvalidArgumentException'); $this->factory->setConstraintClass('string', 'JsonSchema\Tests\Constraints\MyBadConstraint'); } From f21197f3f0b843a8252b6934f662d0622efe61a9 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:15:47 +0900 Subject: [PATCH 12/29] Bump PHPUnit a bit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 88d25730..930c72ba 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 <10", + "phpunit/phpunit": ">=4.8.36 <10", "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1", "phpspec/prophecy-phpunit": ">=1.0" }, From 8436a4818de7cb7d95f5c53abcc7ef843adb3fc3 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:24:11 +0900 Subject: [PATCH 13/29] We have to use PolyfillTrait --- composer.json | 3 ++- tests/ConstraintErrorTest.php | 3 +++ tests/Constraints/FactoryTest.php | 3 +++ tests/Constraints/SchemaValidationTest.php | 3 +++ tests/Constraints/SelfDefinedSchemaTest.php | 3 +++ tests/Constraints/TypeTest.php | 3 +++ tests/Constraints/ValidationExceptionTest.php | 3 +++ tests/Entity/JsonPointerTest.php | 3 +++ tests/RefTest.php | 3 +++ 9 files changed, 26 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 930c72ba..2a3cf773 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ "json-schema/json-schema-test-suite": "1.2.0", "phpunit/phpunit": ">=4.8.36 <10", "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1", - "phpspec/prophecy-phpunit": ">=1.0" + "phpspec/prophecy-phpunit": ">=1.0", + "phpunitgoodpractices/polyfill": "^1.6" }, "extra": { "branch-alias": { diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index 52a3e8b0..b5e8a5a5 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -11,9 +11,12 @@ use JsonSchema\ConstraintError; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class ConstraintErrorTest extends TestCase { + use PolyfillTrait; + public function testGetValidMessage() { $e = ConstraintError::ALL_OF(); diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index a8c4f038..40703d18 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -13,6 +13,7 @@ use JsonSchema\Constraints\Factory; use JsonSchema\Entity\JsonPointer; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * Class MyBadConstraint @@ -37,6 +38,8 @@ public function check(&$value, $schema = null, JsonPointer $path = null, $i = nu class FactoryTest extends TestCase { + use PolyfillTrait; + /** * @var Factory */ diff --git a/tests/Constraints/SchemaValidationTest.php b/tests/Constraints/SchemaValidationTest.php index 0330bb3d..c7993dd9 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -12,9 +12,12 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Validator; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class SchemaValidationTest extends TestCase { + use PolyfillTrait; + protected $validateSchema = true; public function getInvalidTests() diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index 2dc4871b..aa2ca015 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -10,9 +10,12 @@ namespace JsonSchema\Tests\Constraints; use JsonSchema\Validator; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class SelfDefinedSchemaTest extends BaseTestCase { + use PolyfillTrait; + protected $validateSchema = true; public function getInvalidTests() diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index 9256e533..78f4f240 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -12,6 +12,7 @@ use JsonSchema\Constraints\TypeCheck\LooseTypeCheck; use JsonSchema\Constraints\TypeConstraint; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * Class TypeTest @@ -22,6 +23,8 @@ */ class TypeTest extends TestCase { + use PolyfillTrait; + /** * @see testIndefiniteArticleForTypeInTypeCheckErrorMessage * diff --git a/tests/Constraints/ValidationExceptionTest.php b/tests/Constraints/ValidationExceptionTest.php index 1c928d1f..62e4702a 100644 --- a/tests/Constraints/ValidationExceptionTest.php +++ b/tests/Constraints/ValidationExceptionTest.php @@ -13,9 +13,12 @@ use JsonSchema\Exception\ValidationException; use JsonSchema\Validator; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class ValidationExceptionTest extends TestCase { + use PolyfillTrait; + public function testValidationException() { $exception = new ValidationException(); diff --git a/tests/Entity/JsonPointerTest.php b/tests/Entity/JsonPointerTest.php index 413c3ddd..bb4aa6d3 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -11,6 +11,7 @@ use JsonSchema\Entity\JsonPointer; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * @package JsonSchema\Tests\Entity @@ -19,6 +20,8 @@ */ class JsonPointerTest extends TestCase { + use PolyfillTrait; + /** * @dataProvider getTestData * diff --git a/tests/RefTest.php b/tests/RefTest.php index 153b32e9..0c3652b8 100644 --- a/tests/RefTest.php +++ b/tests/RefTest.php @@ -11,9 +11,12 @@ use JsonSchema\Validator; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class RefTest extends TestCase { + use PolyfillTrait; + public function dataRefIgnoresSiblings() { return array( From 01ec2c9dfb9d2054de93aa9cee99268735c14552 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:33:12 +0900 Subject: [PATCH 14/29] Use bundleted trait instead --- composer.json | 3 +- tests/ConstraintErrorTest.php | 1 - tests/Constraints/FactoryTest.php | 2 +- tests/Constraints/SchemaValidationTest.php | 2 +- tests/Constraints/SelfDefinedSchemaTest.php | 2 +- tests/Constraints/TypeTest.php | 2 +- tests/Constraints/ValidationExceptionTest.php | 2 +- tests/Entity/JsonPointerTest.php | 2 +- tests/PolyfillTrait.php | 42 +++++++++++++++++++ tests/RefTest.php | 1 - 10 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 tests/PolyfillTrait.php diff --git a/composer.json b/composer.json index 2a3cf773..930c72ba 100644 --- a/composer.json +++ b/composer.json @@ -36,8 +36,7 @@ "json-schema/json-schema-test-suite": "1.2.0", "phpunit/phpunit": ">=4.8.36 <10", "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1", - "phpspec/prophecy-phpunit": ">=1.0", - "phpunitgoodpractices/polyfill": "^1.6" + "phpspec/prophecy-phpunit": ">=1.0" }, "extra": { "branch-alias": { diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index b5e8a5a5..993bbada 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -11,7 +11,6 @@ use JsonSchema\ConstraintError; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class ConstraintErrorTest extends TestCase { diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index 40703d18..ab18b2ba 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -12,8 +12,8 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Constraints\Factory; use JsonSchema\Entity\JsonPointer; +use JsonSchema\Tests\PolyfillTrait; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * Class MyBadConstraint diff --git a/tests/Constraints/SchemaValidationTest.php b/tests/Constraints/SchemaValidationTest.php index c7993dd9..2d065616 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -10,9 +10,9 @@ namespace JsonSchema\Tests\Constraints; use JsonSchema\Constraints\Constraint; +use JsonSchema\Tests\PolyfillTrait; use JsonSchema\Validator; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class SchemaValidationTest extends TestCase { diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index aa2ca015..a87841ef 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -9,8 +9,8 @@ namespace JsonSchema\Tests\Constraints; +use JsonSchema\Tests\PolyfillTrait; use JsonSchema\Validator; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class SelfDefinedSchemaTest extends BaseTestCase { diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index 78f4f240..72c714ee 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -11,8 +11,8 @@ use JsonSchema\Constraints\TypeCheck\LooseTypeCheck; use JsonSchema\Constraints\TypeConstraint; +use JsonSchema\Tests\PolyfillTrait; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * Class TypeTest diff --git a/tests/Constraints/ValidationExceptionTest.php b/tests/Constraints/ValidationExceptionTest.php index 62e4702a..afce6601 100644 --- a/tests/Constraints/ValidationExceptionTest.php +++ b/tests/Constraints/ValidationExceptionTest.php @@ -11,9 +11,9 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Exception\ValidationException; +use JsonSchema\Tests\PolyfillTrait; use JsonSchema\Validator; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class ValidationExceptionTest extends TestCase { diff --git a/tests/Entity/JsonPointerTest.php b/tests/Entity/JsonPointerTest.php index bb4aa6d3..f15b5721 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -10,8 +10,8 @@ namespace JsonSchema\Tests\Entity; use JsonSchema\Entity\JsonPointer; +use JsonSchema\Tests\PolyfillTrait; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * @package JsonSchema\Tests\Entity diff --git a/tests/PolyfillTrait.php b/tests/PolyfillTrait.php new file mode 100644 index 00000000..11622303 --- /dev/null +++ b/tests/PolyfillTrait.php @@ -0,0 +1,42 @@ +setExpectedException($exception); + } + } + + public static function assertIsArray($actual, $message = '') + { + if (\is_callable(array(parent::class, 'assertIsArray'))) { + parent::assertIsArray($actual, $message); + } else { + static::assertInternalType('array', $actual, $message); + } + } + } +} else { + trait PolyfillTrait + { + } +} diff --git a/tests/RefTest.php b/tests/RefTest.php index 0c3652b8..a4d7641b 100644 --- a/tests/RefTest.php +++ b/tests/RefTest.php @@ -11,7 +11,6 @@ use JsonSchema\Validator; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class RefTest extends TestCase { From a9eae67d0dd0aad82a23813695833bbc86015cab Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:34:53 +0900 Subject: [PATCH 15/29] Use vendored phpunit --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 930c72ba..3cb8669f 100644 --- a/composer.json +++ b/composer.json @@ -71,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" } } From d31898e0bf116e1b25020365ebbbffeb9f207f3c Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:38:06 +0900 Subject: [PATCH 16/29] Just use the polyfill all the time --- tests/PolyfillTrait.php | 44 ++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/tests/PolyfillTrait.php b/tests/PolyfillTrait.php index 11622303..0fa46e84 100644 --- a/tests/PolyfillTrait.php +++ b/tests/PolyfillTrait.php @@ -9,34 +9,28 @@ namespace JsonSchema\Tests; -if (version_compare(\PHPUnit\Runner\Version::id(), '6.0.0') < 0) { - /** - * Inspired by https://github.com/PHPUnitGoodPractices/polyfill - * - * @license MIT - */ - trait PolyfillTrait +/** + * Inspired by https://github.com/PHPUnitGoodPractices/polyfill + * + * @license MIT + */ +trait PolyfillTrait +{ + public function expectException($exception) { - public function expectException($exception) - { - if (\is_callable(array(parent::class, 'expectException'))) { - parent::expectException($exception); - } else { - $this->setExpectedException($exception); - } - } - - public static function assertIsArray($actual, $message = '') - { - if (\is_callable(array(parent::class, 'assertIsArray'))) { - parent::assertIsArray($actual, $message); - } else { - static::assertInternalType('array', $actual, $message); - } + if (\is_callable(array('PHPUnit\Framework\TestCase', 'expectException'))) { + parent::expectException($exception); + } else { + $this->setExpectedException($exception); } } -} else { - trait PolyfillTrait + + public static function assertIsArray($actual, $message = '') { + if (\is_callable(array('PHPUnit\Framework\TestCase', 'assertIsArray'))) { + parent::assertIsArray($actual, $message); + } else { + static::assertInternalType('array', $actual, $message); + } } } From 7f8b32fe0473a2acd0f2032db65f2469f5290ee4 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:41:31 +0900 Subject: [PATCH 17/29] Bummer, we still need to account for return void --- tests/PolyfillTrait.php | 44 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/tests/PolyfillTrait.php b/tests/PolyfillTrait.php index 0fa46e84..8e7d4420 100644 --- a/tests/PolyfillTrait.php +++ b/tests/PolyfillTrait.php @@ -9,28 +9,34 @@ namespace JsonSchema\Tests; -/** - * Inspired by https://github.com/PHPUnitGoodPractices/polyfill - * - * @license MIT - */ -trait PolyfillTrait -{ - public function expectException($exception) +if (version_compare(PHP_VERSION, '7.4.0') < 0) { + /** + * Inspired by https://github.com/PHPUnitGoodPractices/polyfill + * + * @license MIT + */ + trait PolyfillTrait { - if (\is_callable(array('PHPUnit\Framework\TestCase', 'expectException'))) { - parent::expectException($exception); - } else { - $this->setExpectedException($exception); + public function expectException($exception) + { + if (\is_callable(array('PHPUnit\Framework\TestCase', 'expectException'))) { + parent::expectException($exception); + } else { + $this->setExpectedException($exception); + } } - } - public static function assertIsArray($actual, $message = '') - { - if (\is_callable(array('PHPUnit\Framework\TestCase', 'assertIsArray'))) { - parent::assertIsArray($actual, $message); - } else { - static::assertInternalType('array', $actual, $message); + public static function assertIsArray($actual, $message = '') + { + if (\is_callable(array('PHPUnit\Framework\TestCase', 'assertIsArray'))) { + parent::assertIsArray($actual, $message); + } else { + static::assertInternalType('array', $actual, $message); + } } } +} else { + trait PolyfillTrait + { + } } From ab4622db46742631efa5d80ad9e9fe121218908e Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:43:41 +0900 Subject: [PATCH 18/29] Try with PHP 7.1 as lowest --- tests/PolyfillTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PolyfillTrait.php b/tests/PolyfillTrait.php index 8e7d4420..365c9c5a 100644 --- a/tests/PolyfillTrait.php +++ b/tests/PolyfillTrait.php @@ -9,7 +9,7 @@ namespace JsonSchema\Tests; -if (version_compare(PHP_VERSION, '7.4.0') < 0) { +if (version_compare(PHP_VERSION, '7.1.0') < 0) { /** * Inspired by https://github.com/PHPUnitGoodPractices/polyfill * From 52640e1aa2f76dcfc6b72b848bde8a05ac3e9390 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:46:06 +0900 Subject: [PATCH 19/29] Revert "Try with PHP 7.1 as lowest" This reverts commit ab4622db46742631efa5d80ad9e9fe121218908e. --- tests/PolyfillTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PolyfillTrait.php b/tests/PolyfillTrait.php index 365c9c5a..8e7d4420 100644 --- a/tests/PolyfillTrait.php +++ b/tests/PolyfillTrait.php @@ -9,7 +9,7 @@ namespace JsonSchema\Tests; -if (version_compare(PHP_VERSION, '7.1.0') < 0) { +if (version_compare(PHP_VERSION, '7.4.0') < 0) { /** * Inspired by https://github.com/PHPUnitGoodPractices/polyfill * From 44cc0116aa504913f73cd8165f6fff89a44fe27c Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:46:13 +0900 Subject: [PATCH 20/29] Revert "Bummer, we still need to account for return void" This reverts commit 7f8b32fe0473a2acd0f2032db65f2469f5290ee4. --- tests/PolyfillTrait.php | 44 ++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/tests/PolyfillTrait.php b/tests/PolyfillTrait.php index 8e7d4420..0fa46e84 100644 --- a/tests/PolyfillTrait.php +++ b/tests/PolyfillTrait.php @@ -9,34 +9,28 @@ namespace JsonSchema\Tests; -if (version_compare(PHP_VERSION, '7.4.0') < 0) { - /** - * Inspired by https://github.com/PHPUnitGoodPractices/polyfill - * - * @license MIT - */ - trait PolyfillTrait +/** + * Inspired by https://github.com/PHPUnitGoodPractices/polyfill + * + * @license MIT + */ +trait PolyfillTrait +{ + public function expectException($exception) { - public function expectException($exception) - { - if (\is_callable(array('PHPUnit\Framework\TestCase', 'expectException'))) { - parent::expectException($exception); - } else { - $this->setExpectedException($exception); - } - } - - public static function assertIsArray($actual, $message = '') - { - if (\is_callable(array('PHPUnit\Framework\TestCase', 'assertIsArray'))) { - parent::assertIsArray($actual, $message); - } else { - static::assertInternalType('array', $actual, $message); - } + if (\is_callable(array('PHPUnit\Framework\TestCase', 'expectException'))) { + parent::expectException($exception); + } else { + $this->setExpectedException($exception); } } -} else { - trait PolyfillTrait + + public static function assertIsArray($actual, $message = '') { + if (\is_callable(array('PHPUnit\Framework\TestCase', 'assertIsArray'))) { + parent::assertIsArray($actual, $message); + } else { + static::assertInternalType('array', $actual, $message); + } } } From c980858678677914de080a00dfd79d0e3ab0dd08 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:46:23 +0900 Subject: [PATCH 21/29] Revert "Just use the polyfill all the time" This reverts commit d31898e0bf116e1b25020365ebbbffeb9f207f3c. --- tests/PolyfillTrait.php | 44 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/tests/PolyfillTrait.php b/tests/PolyfillTrait.php index 0fa46e84..11622303 100644 --- a/tests/PolyfillTrait.php +++ b/tests/PolyfillTrait.php @@ -9,28 +9,34 @@ namespace JsonSchema\Tests; -/** - * Inspired by https://github.com/PHPUnitGoodPractices/polyfill - * - * @license MIT - */ -trait PolyfillTrait -{ - public function expectException($exception) +if (version_compare(\PHPUnit\Runner\Version::id(), '6.0.0') < 0) { + /** + * Inspired by https://github.com/PHPUnitGoodPractices/polyfill + * + * @license MIT + */ + trait PolyfillTrait { - if (\is_callable(array('PHPUnit\Framework\TestCase', 'expectException'))) { - parent::expectException($exception); - } else { - $this->setExpectedException($exception); + public function expectException($exception) + { + if (\is_callable(array(parent::class, 'expectException'))) { + parent::expectException($exception); + } else { + $this->setExpectedException($exception); + } } - } - public static function assertIsArray($actual, $message = '') - { - if (\is_callable(array('PHPUnit\Framework\TestCase', 'assertIsArray'))) { - parent::assertIsArray($actual, $message); - } else { - static::assertInternalType('array', $actual, $message); + public static function assertIsArray($actual, $message = '') + { + if (\is_callable(array(parent::class, 'assertIsArray'))) { + parent::assertIsArray($actual, $message); + } else { + static::assertInternalType('array', $actual, $message); + } } } +} else { + trait PolyfillTrait + { + } } From c52483b49b953438816e89a57fd119ff209882fd Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:46:29 +0900 Subject: [PATCH 22/29] Revert "Use bundleted trait instead" This reverts commit 01ec2c9dfb9d2054de93aa9cee99268735c14552. --- composer.json | 3 +- tests/ConstraintErrorTest.php | 1 + tests/Constraints/FactoryTest.php | 2 +- tests/Constraints/SchemaValidationTest.php | 2 +- tests/Constraints/SelfDefinedSchemaTest.php | 2 +- tests/Constraints/TypeTest.php | 2 +- tests/Constraints/ValidationExceptionTest.php | 2 +- tests/Entity/JsonPointerTest.php | 2 +- tests/PolyfillTrait.php | 42 ------------------- tests/RefTest.php | 1 + 10 files changed, 10 insertions(+), 49 deletions(-) delete mode 100644 tests/PolyfillTrait.php diff --git a/composer.json b/composer.json index 3cb8669f..cd631ace 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ "json-schema/json-schema-test-suite": "1.2.0", "phpunit/phpunit": ">=4.8.36 <10", "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1", - "phpspec/prophecy-phpunit": ">=1.0" + "phpspec/prophecy-phpunit": ">=1.0", + "phpunitgoodpractices/polyfill": "^1.6" }, "extra": { "branch-alias": { diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index 993bbada..b5e8a5a5 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -11,6 +11,7 @@ use JsonSchema\ConstraintError; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class ConstraintErrorTest extends TestCase { diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index ab18b2ba..40703d18 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -12,8 +12,8 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Constraints\Factory; use JsonSchema\Entity\JsonPointer; -use JsonSchema\Tests\PolyfillTrait; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * Class MyBadConstraint diff --git a/tests/Constraints/SchemaValidationTest.php b/tests/Constraints/SchemaValidationTest.php index 2d065616..c7993dd9 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -10,9 +10,9 @@ namespace JsonSchema\Tests\Constraints; use JsonSchema\Constraints\Constraint; -use JsonSchema\Tests\PolyfillTrait; use JsonSchema\Validator; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class SchemaValidationTest extends TestCase { diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index a87841ef..aa2ca015 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -9,8 +9,8 @@ namespace JsonSchema\Tests\Constraints; -use JsonSchema\Tests\PolyfillTrait; use JsonSchema\Validator; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class SelfDefinedSchemaTest extends BaseTestCase { diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index 72c714ee..78f4f240 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -11,8 +11,8 @@ use JsonSchema\Constraints\TypeCheck\LooseTypeCheck; use JsonSchema\Constraints\TypeConstraint; -use JsonSchema\Tests\PolyfillTrait; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * Class TypeTest diff --git a/tests/Constraints/ValidationExceptionTest.php b/tests/Constraints/ValidationExceptionTest.php index afce6601..62e4702a 100644 --- a/tests/Constraints/ValidationExceptionTest.php +++ b/tests/Constraints/ValidationExceptionTest.php @@ -11,9 +11,9 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Exception\ValidationException; -use JsonSchema\Tests\PolyfillTrait; use JsonSchema\Validator; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class ValidationExceptionTest extends TestCase { diff --git a/tests/Entity/JsonPointerTest.php b/tests/Entity/JsonPointerTest.php index f15b5721..bb4aa6d3 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -10,8 +10,8 @@ namespace JsonSchema\Tests\Entity; use JsonSchema\Entity\JsonPointer; -use JsonSchema\Tests\PolyfillTrait; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * @package JsonSchema\Tests\Entity diff --git a/tests/PolyfillTrait.php b/tests/PolyfillTrait.php deleted file mode 100644 index 11622303..00000000 --- a/tests/PolyfillTrait.php +++ /dev/null @@ -1,42 +0,0 @@ -setExpectedException($exception); - } - } - - public static function assertIsArray($actual, $message = '') - { - if (\is_callable(array(parent::class, 'assertIsArray'))) { - parent::assertIsArray($actual, $message); - } else { - static::assertInternalType('array', $actual, $message); - } - } - } -} else { - trait PolyfillTrait - { - } -} diff --git a/tests/RefTest.php b/tests/RefTest.php index a4d7641b..0c3652b8 100644 --- a/tests/RefTest.php +++ b/tests/RefTest.php @@ -11,6 +11,7 @@ use JsonSchema\Validator; use LegacyPHPUnit\TestCase; +use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class RefTest extends TestCase { From 872b34ca3909cc50337a8644a4dd4e96154fa283 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:46:50 +0900 Subject: [PATCH 23/29] Revert "We have to use PolyfillTrait" This reverts commit 8436a4818de7cb7d95f5c53abcc7ef843adb3fc3. --- composer.json | 3 +-- tests/ConstraintErrorTest.php | 3 --- tests/Constraints/FactoryTest.php | 3 --- tests/Constraints/SchemaValidationTest.php | 3 --- tests/Constraints/SelfDefinedSchemaTest.php | 3 --- tests/Constraints/TypeTest.php | 3 --- tests/Constraints/ValidationExceptionTest.php | 3 --- tests/Entity/JsonPointerTest.php | 3 --- tests/RefTest.php | 3 --- 9 files changed, 1 insertion(+), 26 deletions(-) diff --git a/composer.json b/composer.json index cd631ace..3cb8669f 100644 --- a/composer.json +++ b/composer.json @@ -36,8 +36,7 @@ "json-schema/json-schema-test-suite": "1.2.0", "phpunit/phpunit": ">=4.8.36 <10", "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1", - "phpspec/prophecy-phpunit": ">=1.0", - "phpunitgoodpractices/polyfill": "^1.6" + "phpspec/prophecy-phpunit": ">=1.0" }, "extra": { "branch-alias": { diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index b5e8a5a5..52a3e8b0 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -11,12 +11,9 @@ use JsonSchema\ConstraintError; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class ConstraintErrorTest extends TestCase { - use PolyfillTrait; - public function testGetValidMessage() { $e = ConstraintError::ALL_OF(); diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index 40703d18..a8c4f038 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -13,7 +13,6 @@ use JsonSchema\Constraints\Factory; use JsonSchema\Entity\JsonPointer; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * Class MyBadConstraint @@ -38,8 +37,6 @@ public function check(&$value, $schema = null, JsonPointer $path = null, $i = nu class FactoryTest extends TestCase { - use PolyfillTrait; - /** * @var Factory */ diff --git a/tests/Constraints/SchemaValidationTest.php b/tests/Constraints/SchemaValidationTest.php index c7993dd9..0330bb3d 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -12,12 +12,9 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Validator; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class SchemaValidationTest extends TestCase { - use PolyfillTrait; - protected $validateSchema = true; public function getInvalidTests() diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index aa2ca015..2dc4871b 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -10,12 +10,9 @@ namespace JsonSchema\Tests\Constraints; use JsonSchema\Validator; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class SelfDefinedSchemaTest extends BaseTestCase { - use PolyfillTrait; - protected $validateSchema = true; public function getInvalidTests() diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index 78f4f240..9256e533 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -12,7 +12,6 @@ use JsonSchema\Constraints\TypeCheck\LooseTypeCheck; use JsonSchema\Constraints\TypeConstraint; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * Class TypeTest @@ -23,8 +22,6 @@ */ class TypeTest extends TestCase { - use PolyfillTrait; - /** * @see testIndefiniteArticleForTypeInTypeCheckErrorMessage * diff --git a/tests/Constraints/ValidationExceptionTest.php b/tests/Constraints/ValidationExceptionTest.php index 62e4702a..1c928d1f 100644 --- a/tests/Constraints/ValidationExceptionTest.php +++ b/tests/Constraints/ValidationExceptionTest.php @@ -13,12 +13,9 @@ use JsonSchema\Exception\ValidationException; use JsonSchema\Validator; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class ValidationExceptionTest extends TestCase { - use PolyfillTrait; - public function testValidationException() { $exception = new ValidationException(); diff --git a/tests/Entity/JsonPointerTest.php b/tests/Entity/JsonPointerTest.php index bb4aa6d3..413c3ddd 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -11,7 +11,6 @@ use JsonSchema\Entity\JsonPointer; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; /** * @package JsonSchema\Tests\Entity @@ -20,8 +19,6 @@ */ class JsonPointerTest extends TestCase { - use PolyfillTrait; - /** * @dataProvider getTestData * diff --git a/tests/RefTest.php b/tests/RefTest.php index 0c3652b8..153b32e9 100644 --- a/tests/RefTest.php +++ b/tests/RefTest.php @@ -11,12 +11,9 @@ use JsonSchema\Validator; use LegacyPHPUnit\TestCase; -use PHPUnitGoodPractices\Polyfill\PolyfillTrait; class RefTest extends TestCase { - use PolyfillTrait; - public function dataRefIgnoresSiblings() { return array( From 095ae9141413a145d48115b1a1e8741e6c24a200 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 10:49:44 +0900 Subject: [PATCH 24/29] Can't use traits in PHP 5.3 --- composer.json | 4 ++-- tests/Constraints/VeryBaseTestCase.php | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3cb8669f..147ff155 100644 --- a/composer.json +++ b/composer.json @@ -34,9 +34,9 @@ "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.36 <10", + "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.0" + "phpspec/prophecy-phpunit": "^1.1 || ^2.0.1" }, "extra": { "branch-alias": { diff --git a/tests/Constraints/VeryBaseTestCase.php b/tests/Constraints/VeryBaseTestCase.php index 3b5c4cdb..daa6e856 100644 --- a/tests/Constraints/VeryBaseTestCase.php +++ b/tests/Constraints/VeryBaseTestCase.php @@ -87,4 +87,23 @@ private function getJsonSchemaDraft04() return $this->jsonSchemaDraft04; } + + public function expectException($exception) + { + if (\is_callable([parent::class, 'expectException'])) { + parent::expectException($exception); + } else { + $this->setExpectedException($exception); + } + } + + public static function assertIsArray($actual, $message = '') + { + if (\is_callable([parent::class, 'assertIsArray'])) { + parent::assertIsArray($actual, $message); + } else { + static::assertInternalType('array', $actual, $message); + } + } + } From 43505622293fc95ef8f97cc15516862953e54486 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 11:12:18 +0900 Subject: [PATCH 25/29] Use compat methods --- tests/ConstraintErrorTest.php | 6 +++--- tests/Constraints/FactoryTest.php | 9 ++++----- tests/Constraints/SchemaValidationTest.php | 7 +++---- tests/Constraints/SelfDefinedSchemaTest.php | 2 +- tests/Constraints/TypeTest.php | 9 ++++----- tests/Constraints/ValidationExceptionTest.php | 5 ++--- tests/Constraints/VeryBaseTestCase.php | 9 ++++----- tests/Entity/JsonPointerTest.php | 6 +++--- tests/RefTest.php | 6 +++--- tests/SchemaStorageTest.php | 8 ++++---- tests/Uri/Retrievers/CurlTest.php | 6 +++--- tests/Uri/Retrievers/FileGetContentsTest.php | 12 ++++++------ tests/Uri/Retrievers/PredefinedArrayTest.php | 6 +++--- tests/Uri/UriResolverTest.php | 6 +++--- tests/Uri/UriRetrieverTest.php | 18 +++++++++--------- tests/ValidatorTest.php | 6 +++--- 16 files changed, 58 insertions(+), 63 deletions(-) diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index 52a3e8b0..b6b962f8 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -10,9 +10,9 @@ namespace JsonSchema\Tests; use JsonSchema\ConstraintError; -use LegacyPHPUnit\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->expectException( + $this->expectExceptionCompat( '\JsonSchema\Exception\InvalidArgumentException', 'Missing error message for missingError' ); diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index a8c4f038..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 LegacyPHPUnit\TestCase; /** * Class MyBadConstraint @@ -35,7 +34,7 @@ public function check(&$value, $schema = null, JsonPointer $path = null, $i = nu } } -class FactoryTest extends TestCase +class FactoryTest extends VeryBaseTestCase { /** * @var Factory @@ -85,7 +84,7 @@ public function constraintNameProvider() */ public function testExceptionWhenCreateInstanceForInvalidConstraintName($constraintName) { - $this->expectException('JsonSchema\Exception\InvalidArgumentException'); + $this->expectExceptionCompat('JsonSchema\Exception\InvalidArgumentException'); $this->factory->createInstanceFor($constraintName); } @@ -98,14 +97,14 @@ public function invalidConstraintNameProvider() public function testSetConstraintClassExistsCondition() { - $this->expectException('\JsonSchema\Exception\InvalidArgumentException'); + $this->expectExceptionCompat('\JsonSchema\Exception\InvalidArgumentException'); $this->factory->setConstraintClass('string', 'SomeConstraint'); } public function testSetConstraintClassImplementsCondition() { - $this->expectException('\JsonSchema\Exception\InvalidArgumentException'); + $this->expectExceptionCompat('\JsonSchema\Exception\InvalidArgumentException'); $this->factory->setConstraintClass('string', 'JsonSchema\Tests\Constraints\MyBadConstraint'); } diff --git a/tests/Constraints/SchemaValidationTest.php b/tests/Constraints/SchemaValidationTest.php index 0330bb3d..9ef05290 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -11,9 +11,8 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Validator; -use LegacyPHPUnit\TestCase; -class SchemaValidationTest extends TestCase +class SchemaValidationTest extends VeryBaseTestCase { protected $validateSchema = true; @@ -102,7 +101,7 @@ public function testValidCases($schema) public function testNonObjectSchema() { - $this->expectException( + $this->expectExceptionCompat( '\JsonSchema\Exception\RuntimeException', 'Cannot validate the schema of a non-object' ); @@ -111,7 +110,7 @@ public function testNonObjectSchema() public function testInvalidSchemaException() { - $this->expectException( + $this->expectExceptionCompat( '\JsonSchema\Exception\InvalidSchemaException', 'Schema did not pass validation' ); diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index 2dc4871b..5c5a2cc0 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -74,7 +74,7 @@ public function testInvalidArgumentException() $v = new Validator(); - $this->expectException('\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 9256e533..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 LegacyPHPUnit\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->assertIsArray($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->expectException( + $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->expectException( + $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 1c928d1f..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 LegacyPHPUnit\TestCase; -class ValidationExceptionTest extends TestCase +class ValidationExceptionTest extends VeryBaseTestCase { public function testValidationException() { @@ -45,7 +44,7 @@ public function testValidationException() $exception->getMessage() ); - $this->expectException('JsonSchema\Exception\ValidationException'); + $this->expectExceptionCompat('JsonSchema\Exception\ValidationException'); throw $exception; } } diff --git a/tests/Constraints/VeryBaseTestCase.php b/tests/Constraints/VeryBaseTestCase.php index daa6e856..71df3675 100644 --- a/tests/Constraints/VeryBaseTestCase.php +++ b/tests/Constraints/VeryBaseTestCase.php @@ -88,22 +88,21 @@ private function getJsonSchemaDraft04() return $this->jsonSchemaDraft04; } - public function expectException($exception) + public function expectExceptionCompat($exception) { - if (\is_callable([parent::class, 'expectException'])) { + if (\is_callable(array('PHPUnit\Framework\TestCase', 'expectException'))) { parent::expectException($exception); } else { $this->setExpectedException($exception); } } - public static function assertIsArray($actual, $message = '') + public static function assertIsArrayCompat($actual, $message = '') { - if (\is_callable([parent::class, 'assertIsArray'])) { + 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 413c3ddd..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 LegacyPHPUnit\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->expectException( + $this->expectExceptionCompat( '\JsonSchema\Exception\InvalidArgumentException', 'Ref value must be a string' ); diff --git a/tests/RefTest.php b/tests/RefTest.php index 153b32e9..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 LegacyPHPUnit\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->expectException($exception); + $this->expectExceptionCompat($exception); } $v->validate($document, $schema); diff --git a/tests/SchemaStorageTest.php b/tests/SchemaStorageTest.php index 49da3c50..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 LegacyPHPUnit\TestCase; -class SchemaStorageTest extends TestCase +class SchemaStorageTest extends VeryBaseTestCase { public function testResolveRef() { @@ -102,7 +102,7 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference() public function testUnresolvableJsonPointExceptionShouldBeThrown() { - $this->expectException( + $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->expectException( + $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 00417164..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 LegacyPHPUnit\TestCase; - class CurlTest extends TestCase + class CurlTest extends VeryBaseTestCase { public function testRetrieveFile() { @@ -17,7 +17,7 @@ public function testRetrieveNonexistantFile() { $c = new Curl(); - $this->expectException( + $this->expectExceptionCompat( '\JsonSchema\Exception\ResourceNotFoundException', 'JSON schema not found' ); diff --git a/tests/Uri/Retrievers/FileGetContentsTest.php b/tests/Uri/Retrievers/FileGetContentsTest.php index 33a44864..a80b08d2 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -2,19 +2,19 @@ namespace JsonSchema\Tests\Uri\Retrievers { - use JsonSchema\Uri\Retrievers\FileGetContents; - use LegacyPHPUnit\TestCase; + use JsonSchema\Tests\Constraints\VeryBaseTestCase; +use JsonSchema\Uri\Retrievers\FileGetContents; /** * @group FileGetContents */ - class FileGetContentsTest extends TestCase + class FileGetContentsTest extends VeryBaseTestCase { public function testFetchMissingFile() { $res = new FileGetContents(); - $this->expectException('\JsonSchema\Exception\ResourceNotFoundException'); + $this->expectExceptionCompat('\JsonSchema\Exception\ResourceNotFoundException'); $res->retrieve(__DIR__ . '/Fixture/missing.json'); } @@ -29,7 +29,7 @@ public function testFalseReturn() { $res = new FileGetContents(); - $this->expectException( + $this->expectExceptionCompat( '\JsonSchema\Exception\ResourceNotFoundException', 'JSON schema not found at http://example.com/false' ); @@ -40,7 +40,7 @@ public function testFetchDirectory() { $res = new FileGetContents(); - $this->expectException( + $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 f0538161..25006d24 100644 --- a/tests/Uri/Retrievers/PredefinedArrayTest.php +++ b/tests/Uri/Retrievers/PredefinedArrayTest.php @@ -2,13 +2,13 @@ namespace JsonSchema\Tests\Uri\Retrievers; +use JsonSchema\Tests\Constraints\VeryBaseTestCase; use JsonSchema\Uri\Retrievers\PredefinedArray; -use LegacyPHPUnit\TestCase; /** * @group PredefinedArray */ -class PredefinedArrayTest extends TestCase +class PredefinedArrayTest extends VeryBaseTestCase { private $retriever; @@ -31,7 +31,7 @@ public function testRetrieve() public function testRetrieveNonExistsingSchema() { - $this->expectException('\JsonSchema\Exception\ResourceNotFoundException'); + $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 47df3df3..652b8c60 100644 --- a/tests/Uri/UriResolverTest.php +++ b/tests/Uri/UriResolverTest.php @@ -2,10 +2,10 @@ namespace JsonSchema\Tests\Uri; +use JsonSchema\Tests\Constraints\VeryBaseTestCase; use JsonSchema\Uri\UriResolver; -use LegacyPHPUnit\TestCase; -class UriResolverTest extends TestCase +class UriResolverTest extends VeryBaseTestCase { public function doSetUp() { @@ -96,7 +96,7 @@ public function testResolveAbsoluteUri() public function testResolveRelativeUriNoBase() { - $this->expectException('\JsonSchema\Exception\UriResolverException'); + $this->expectExceptionCompat('\JsonSchema\Exception\UriResolverException'); $this->assertEquals( 'http://example.org/foo/bar.json', diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index be55ce30..81424cb0 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -10,14 +10,14 @@ namespace JsonSchema\Tests\Uri; use JsonSchema\Exception\JsonDecodingException; +use JsonSchema\Tests\Constraints\VeryBaseTestCase; use JsonSchema\Uri\UriRetriever; use JsonSchema\Validator; -use LegacyPHPUnit\TestCase; /** * @group UriRetriever */ -class UriRetrieverTest extends TestCase +class UriRetrieverTest extends VeryBaseTestCase { protected $validator; @@ -105,7 +105,7 @@ public function testResolveRelativeUri($childSchema, $parentSchema) $this->assertTrue($this->validator->isValid()); } - private static function setParentSchemaExtendsValue(&$parentSchema, $value) + private static function setParentSchemaExtendsValue(& $parentSchema, $value) { $parentSchemaDecoded = json_decode($parentSchema, true); $parentSchemaDecoded['extends'] = $value; @@ -194,7 +194,7 @@ public function testResolvePointerFragmentNotFound() ); $retriever = new \JsonSchema\Uri\UriRetriever(); - $this->expectException('\JsonSchema\Exception\ResourceNotFoundException'); + $this->expectExceptionCompat('\JsonSchema\Exception\ResourceNotFoundException'); $retriever->resolvePointer( $schema, 'http://example.org/schema.json#/definitions/bar' ); @@ -212,7 +212,7 @@ public function testResolvePointerFragmentNoArray() ); $retriever = new \JsonSchema\Uri\UriRetriever(); - $this->expectException('\JsonSchema\Exception\ResourceNotFoundException'); + $this->expectExceptionCompat('\JsonSchema\Exception\ResourceNotFoundException'); $retriever->resolvePointer( $schema, 'http://example.org/schema.json#/definitions/foo' ); @@ -221,7 +221,7 @@ public function testResolvePointerFragmentNoArray() public function testResolveExcessLevelUp() { $retriever = new \JsonSchema\Uri\UriRetriever(); - $this->expectException('\JsonSchema\Exception\UriResolverException'); + $this->expectExceptionCompat('\JsonSchema\Exception\UriResolverException'); $retriever->resolve( '../schema.json#', 'http://example.org/schema.json#' ); @@ -257,7 +257,7 @@ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() ->method('getContentType') ->will($this->returnValue('text/html')); - $this->expectException('\JsonSchema\Exception\InvalidSchemaMediaTypeException'); + $this->expectExceptionCompat('\JsonSchema\Exception\InvalidSchemaMediaTypeException'); $this->assertEquals(null, $retriever->confirmMediaType($retriever, null)); } @@ -338,7 +338,7 @@ public function testInvalidContentTypeEndpointsUnknown() $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); - $this->expectException('\JsonSchema\Exception\InvalidSchemaMediaTypeException'); + $this->expectExceptionCompat('\JsonSchema\Exception\InvalidSchemaMediaTypeException'); $retriever->confirmMediaType($mock, 'http://example.com'); } @@ -375,7 +375,7 @@ public function testLoadSchemaJSONDecodingException() { $retriever = new UriRetriever(); - $this->expectException( + $this->expectExceptionCompat( 'JsonSchema\Exception\JsonDecodingException', 'JSON syntax is malformed' ); diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index 3ad64492..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 LegacyPHPUnit\TestCase; -class ValidatorTest extends TestCase +class ValidatorTest extends VeryBaseTestCase { public function testValidateWithAssocSchema() { @@ -31,7 +31,7 @@ public function testBadAssocSchemaInput() $validator = new Validator(); - $this->expectException('\JsonSchema\Exception\InvalidArgumentException'); + $this->expectExceptionCompat('\JsonSchema\Exception\InvalidArgumentException'); $validator->validate($data, $schema); } From 7b74df3bbd9577f7c5a24dc98984ce0bb4d0407c Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 11:14:25 +0900 Subject: [PATCH 26/29] 8.1 + lowest-ignore can be built ever --- .github/workflows/continuous-integration.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 7716a088..3e4359bf 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -27,6 +27,7 @@ jobs: - "7.3" - "7.4" - "8.0" + - "8.1" dependencies: [highest] experimental: [false] include: @@ -39,9 +40,6 @@ jobs: - 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 From 4083f14bbd9ee0cfedc664a30cb39ba4c1601191 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 11:18:25 +0900 Subject: [PATCH 27/29] Use getMockCompat --- tests/Constraints/VeryBaseTestCase.php | 9 +++++++++ tests/Uri/UriRetrieverTest.php | 14 +++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/Constraints/VeryBaseTestCase.php b/tests/Constraints/VeryBaseTestCase.php index 71df3675..bd4dbc6d 100644 --- a/tests/Constraints/VeryBaseTestCase.php +++ b/tests/Constraints/VeryBaseTestCase.php @@ -105,4 +105,13 @@ public static function assertIsArrayCompat($actual, $message = '') static::assertInternalType('array', $actual, $message); } } + + public 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/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 81424cb0..16d6e6ab 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -34,7 +34,7 @@ private function getRetrieverMock($returnSchema) throw new JsonDecodingException($error); } - $retriever = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('retrieve')); + $retriever = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('retrieve')); $retriever->expects($this->at(0)) ->method('retrieve') @@ -229,7 +229,7 @@ public function testResolveExcessLevelUp() public function testConfirmMediaTypeAcceptsJsonSchemaType() { - $retriever = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retriever = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('getContentType')); $retriever->expects($this->at(0)) ->method('getContentType') @@ -240,7 +240,7 @@ public function testConfirmMediaTypeAcceptsJsonSchemaType() public function testConfirmMediaTypeAcceptsJsonType() { - $retriever = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retriever = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('getContentType')); $retriever->expects($this->at(0)) ->method('getContentType') @@ -251,7 +251,7 @@ public function testConfirmMediaTypeAcceptsJsonType() public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() { - $retriever = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $retriever = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('getContentType')); $retriever->expects($this->at(0)) ->method('getContentType') @@ -324,7 +324,7 @@ public function testRetrieveSchemaFromPackage() public function testInvalidContentTypeEndpointsDefault() { - $mock = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -334,7 +334,7 @@ public function testInvalidContentTypeEndpointsDefault() public function testInvalidContentTypeEndpointsUnknown() { - $mock = $this->createPartialMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + $mock = $this->getMockCompat('JsonSchema\Uri\UriRetriever', array('getContentType')); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -344,7 +344,7 @@ public function testInvalidContentTypeEndpointsUnknown() public function testInvalidContentTypeEndpointsAdded() { - $mock = $this->createPartialMock('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'); From 3e00bdb6a24da63e81b84902d58934f0a717bc9c Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 11:19:54 +0900 Subject: [PATCH 28/29] Make it private --- tests/Constraints/VeryBaseTestCase.php | 9 --------- tests/Uri/UriRetrieverTest.php | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Constraints/VeryBaseTestCase.php b/tests/Constraints/VeryBaseTestCase.php index bd4dbc6d..71df3675 100644 --- a/tests/Constraints/VeryBaseTestCase.php +++ b/tests/Constraints/VeryBaseTestCase.php @@ -105,13 +105,4 @@ public static function assertIsArrayCompat($actual, $message = '') static::assertInternalType('array', $actual, $message); } } - - public 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/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 16d6e6ab..b33f01a5 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -426,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); + } } From f91116380f9d4ef838f90d8a3b77ed5ff8802539 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 1 Sep 2022 11:21:33 +0900 Subject: [PATCH 29/29] CS --- tests/Uri/UriRetrieverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index b33f01a5..1b842cff 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -105,7 +105,7 @@ public function testResolveRelativeUri($childSchema, $parentSchema) $this->assertTrue($this->validator->isValid()); } - private static function setParentSchemaExtendsValue(& $parentSchema, $value) + private static function setParentSchemaExtendsValue(&$parentSchema, $value) { $parentSchemaDecoded = json_decode($parentSchema, true); $parentSchemaDecoded['extends'] = $value;