feat: add support for PHP 8.2

This commit is contained in:
Romain Canon 2022-10-19 13:32:16 +02:00
parent bd5123390f
commit 47ad4a1416
9 changed files with 98 additions and 7 deletions

View File

@ -5,8 +5,9 @@ jobs:
name: Quality Assurance name: Quality Assurance
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
php-version: '8.1' php-version: '8.2'
php-extensions: yaml php-extensions: yaml
PHP_CS_FIXER_IGNORE_ENV: 1 # @PHP 8.2 remove when PHP-CS-Fixer fully supports PHP 8.2
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3

View File

@ -15,6 +15,7 @@ jobs:
- "7.4" - "7.4"
- "8.0" - "8.0"
- "8.1" - "8.1"
- "8.2"
env: env:
php-extensions: yaml php-extensions: yaml

View File

@ -7,7 +7,10 @@ $finder = PhpCsFixer\Finder::create()->in([
]) ])
->notPath('Fixtures/FunctionWithGroupedImportStatements.php') ->notPath('Fixtures/FunctionWithGroupedImportStatements.php')
->notPath('Fixtures/FunctionWithSeveralImportStatementsInSameUseStatement.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) { if (PHP_VERSION_ID < 8_00_00) {
$finder = $finder $finder = $finder

View File

@ -15,7 +15,7 @@
} }
], ],
"require": { "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", "composer-runtime-api": "^2.0",
"psr/simple-cache": "^1.0 || ^2.0", "psr/simple-cache": "^1.0 || ^2.0",
"doctrine/annotations": "^1.11" "doctrine/annotations": "^1.11"
@ -46,6 +46,7 @@
"scripts": { "scripts": {
"check": [ "check": [
"@putenv XDEBUG_MODE=off", "@putenv XDEBUG_MODE=off",
"@putenv PHP_CS_FIXER_IGNORE_ENV=1",
"phpunit", "phpunit",
"phpstan", "phpstan",
"psalm", "psalm",
@ -54,6 +55,7 @@
], ],
"fix": [ "fix": [
"@putenv XDEBUG_MODE=off", "@putenv XDEBUG_MODE=off",
"@putenv PHP_CS_FIXER_IGNORE_ENV=1",
"php-cs-fixer fix", "php-cs-fixer fix",
"rector" "rector"
], ],

4
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "d9ebcc2e5638317c0dbe69803a3d1522", "content-hash": "5a1c2928cb71d9aca6ace45d1cea6012",
"packages": [ "packages": [
{ {
"name": "doctrine/annotations", "name": "doctrine/annotations",
@ -5823,7 +5823,7 @@
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "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" "composer-runtime-api": "^2.0"
}, },
"platform-dev": [], "platform-dev": [],

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace CuyZ\Valinor\Tests\Fixture\Object;
use Countable;
use DateTime;
use Iterator;
// @PHP8.2 move to anonymous class
final class ObjectWithPropertyWithNativeDisjunctiveNormalFormType
{
public (Countable&Iterator)|(Countable&DateTime) $someProperty;
}

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace CuyZ\Valinor\Tests\Fixture\Object;
// @PHP8.2 move to anonymous class
final class ObjectWithPropertyWithNativePhp82StandaloneTypes
{
public null $nativeNull = null;
public true $nativeTrue;
public false $nativeFalse;
}

View File

@ -66,7 +66,7 @@ final class AttributesCompilerTest extends TestCase
*/ */
public function test_compiles_native_php_attributes_for_class_without_attributes(): void public function test_compiles_native_php_attributes_for_class_without_attributes(): void
{ {
$reflection = new ReflectionClass(stdClass::class); $reflection = new ReflectionClass(new class () { });
$attributes = $this->compile(new NativeAttributes($reflection)); $attributes = $this->compile(new NativeAttributes($reflection));
self::assertInstanceOf(EmptyAttributes::class, $attributes); 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 public function test_compiles_combined_attributes_for_class_without_annotation(): void
{ {
$reflection = new ReflectionClass(stdClass::class); $reflection = new ReflectionClass(new class () { });
$attributes = $this->compile( $attributes = $this->compile(
new CombinedAttributes( new CombinedAttributes(
new DoctrineAnnotations($reflection), new DoctrineAnnotations($reflection),

View File

@ -9,7 +9,9 @@ use CuyZ\Valinor\Tests\Fake\FakeReflector;
use CuyZ\Valinor\Tests\Fixture\Enum\BackedStringEnum; use CuyZ\Valinor\Tests\Fixture\Enum\BackedStringEnum;
use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithConstants; use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithConstants;
use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyPromotion; 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\ObjectWithPropertyWithNativeIntersectionType;
use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyWithNativePhp82StandaloneTypes;
use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyWithNativeUnionType; use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyWithNativeUnionType;
use CuyZ\Valinor\Utility\Reflection\Reflection; use CuyZ\Valinor\Utility\Reflection\Reflection;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -159,6 +161,58 @@ final class ReflectionTest extends TestCase
self::assertSame('Countable&Iterator', Reflection::flattenType($type)); 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 * @param non-empty-string $expectedType
* @dataProvider callables_with_docblock_typed_return_type * @dataProvider callables_with_docblock_typed_return_type