From 47ad4a1416d0e0727e243539258891c87f09e5ce Mon Sep 17 00:00:00 2001 From: Romain Canon Date: Wed, 19 Oct 2022 13:32:16 +0200 Subject: [PATCH] feat: add support for PHP 8.2 --- .github/workflows/quality-assurance.yml | 3 +- .github/workflows/tests.yml | 1 + .php-cs-fixer.dist.php | 5 +- composer.json | 4 +- composer.lock | 4 +- ...rtyWithNativeDisjunctiveNormalFormType.php | 15 ++++++ ...PropertyWithNativePhp82StandaloneTypes.php | 15 ++++++ .../Cache/Compiler/AttributesCompilerTest.php | 4 +- .../Utility/Reflection/ReflectionTest.php | 54 +++++++++++++++++++ 9 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 tests/Fixture/Object/ObjectWithPropertyWithNativeDisjunctiveNormalFormType.php create mode 100644 tests/Fixture/Object/ObjectWithPropertyWithNativePhp82StandaloneTypes.php diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index e98891c..99d89ec 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -5,8 +5,9 @@ jobs: name: Quality Assurance runs-on: ubuntu-latest env: - php-version: '8.1' + php-version: '8.2' php-extensions: yaml + PHP_CS_FIXER_IGNORE_ENV: 1 # @PHP 8.2 remove when PHP-CS-Fixer fully supports PHP 8.2 steps: - name: Checkout uses: actions/checkout@v3 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a391fb8..e786cf7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,6 +15,7 @@ jobs: - "7.4" - "8.0" - "8.1" + - "8.2" env: php-extensions: yaml diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index fad192d..c44cef5 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -7,7 +7,10 @@ $finder = PhpCsFixer\Finder::create()->in([ ]) ->notPath('Fixtures/FunctionWithGroupedImportStatements.php') ->notPath('Fixtures/FunctionWithSeveralImportStatementsInSameUseStatement.php') - ->notPath('Fixtures/TwoClassesInDifferentNamespaces.php'); + ->notPath('Fixtures/TwoClassesInDifferentNamespaces.php') + // @PHP 8.2 remove when PHP-CS-Fixer fully supports PHP 8.2; also remove + // `@putenv PHP_CS_FIXER_IGNORE_ENV=1` inside `composer.json` + ->notPath('Fixture/Object/ObjectWithPropertyWithNativeDisjunctiveNormalFormType.php'); if (PHP_VERSION_ID < 8_00_00) { $finder = $finder diff --git a/composer.json b/composer.json index 5ea18e4..002bdc0 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": "~7.4.0 || ~8.0.0 || ~8.1.0", + "php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0", "composer-runtime-api": "^2.0", "psr/simple-cache": "^1.0 || ^2.0", "doctrine/annotations": "^1.11" @@ -46,6 +46,7 @@ "scripts": { "check": [ "@putenv XDEBUG_MODE=off", + "@putenv PHP_CS_FIXER_IGNORE_ENV=1", "phpunit", "phpstan", "psalm", @@ -54,6 +55,7 @@ ], "fix": [ "@putenv XDEBUG_MODE=off", + "@putenv PHP_CS_FIXER_IGNORE_ENV=1", "php-cs-fixer fix", "rector" ], diff --git a/composer.lock b/composer.lock index 6f60a65..8658cec 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d9ebcc2e5638317c0dbe69803a3d1522", + "content-hash": "5a1c2928cb71d9aca6ace45d1cea6012", "packages": [ { "name": "doctrine/annotations", @@ -5823,7 +5823,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "~7.4.0 || ~8.0.0 || ~8.1.0", + "php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0", "composer-runtime-api": "^2.0" }, "platform-dev": [], diff --git a/tests/Fixture/Object/ObjectWithPropertyWithNativeDisjunctiveNormalFormType.php b/tests/Fixture/Object/ObjectWithPropertyWithNativeDisjunctiveNormalFormType.php new file mode 100644 index 0000000..0f5b37d --- /dev/null +++ b/tests/Fixture/Object/ObjectWithPropertyWithNativeDisjunctiveNormalFormType.php @@ -0,0 +1,15 @@ +compile(new NativeAttributes($reflection)); self::assertInstanceOf(EmptyAttributes::class, $attributes); @@ -181,7 +181,7 @@ final class AttributesCompilerTest extends TestCase */ public function test_compiles_combined_attributes_for_class_without_annotation(): void { - $reflection = new ReflectionClass(stdClass::class); + $reflection = new ReflectionClass(new class () { }); $attributes = $this->compile( new CombinedAttributes( new DoctrineAnnotations($reflection), diff --git a/tests/Unit/Utility/Reflection/ReflectionTest.php b/tests/Unit/Utility/Reflection/ReflectionTest.php index 638cb88..a5827a7 100644 --- a/tests/Unit/Utility/Reflection/ReflectionTest.php +++ b/tests/Unit/Utility/Reflection/ReflectionTest.php @@ -9,7 +9,9 @@ use CuyZ\Valinor\Tests\Fake\FakeReflector; use CuyZ\Valinor\Tests\Fixture\Enum\BackedStringEnum; use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithConstants; use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyPromotion; +use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyWithNativeDisjunctiveNormalFormType; use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyWithNativeIntersectionType; +use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyWithNativePhp82StandaloneTypes; use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyWithNativeUnionType; use CuyZ\Valinor\Utility\Reflection\Reflection; use PHPUnit\Framework\TestCase; @@ -159,6 +161,58 @@ final class ReflectionTest extends TestCase self::assertSame('Countable&Iterator', Reflection::flattenType($type)); } + /** + * @requires PHP >= 8.2 + */ + public function test_disjunctive_normal_form_type_is_handled(): void + { + $class = ObjectWithPropertyWithNativeDisjunctiveNormalFormType::class; + + /** @var ReflectionType $type */ + $type = (new ReflectionProperty($class, 'someProperty'))->getType(); + + self::assertSame('Countable&Iterator|Countable&DateTime', Reflection::flattenType($type)); + } + + /** + * @requires PHP >= 8.2 + */ + public function test_native_null_type_is_handled(): void + { + $class = ObjectWithPropertyWithNativePhp82StandaloneTypes::class; + + /** @var ReflectionType $type */ + $type = (new ReflectionProperty($class, 'nativeNull'))->getType(); + + self::assertSame('null', Reflection::flattenType($type)); + } + + /** + * @requires PHP >= 8.2 + */ + public function test_native_true_type_is_handled(): void + { + $class = ObjectWithPropertyWithNativePhp82StandaloneTypes::class; + + /** @var ReflectionType $type */ + $type = (new ReflectionProperty($class, 'nativeTrue'))->getType(); + + self::assertSame('true', Reflection::flattenType($type)); + } + + /** + * @requires PHP >= 8.2 + */ + public function test_native_false_type_is_handled(): void + { + $class = ObjectWithPropertyWithNativePhp82StandaloneTypes::class; + + /** @var ReflectionType $type */ + $type = (new ReflectionProperty($class, 'nativeFalse'))->getType(); + + self::assertSame('false', Reflection::flattenType($type)); + } + /** * @param non-empty-string $expectedType * @dataProvider callables_with_docblock_typed_return_type