From 5962e1e9696cade004ca94485a1358121d474943 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Wed, 2 Oct 2024 16:14:03 +0200 Subject: [PATCH] Adjust test executions for older PHP versions --- tests/Rule/ForbidNotNormalizedTypeRuleTest.php | 5 +++++ tests/Rule/ForbidUnsafeArrayKeyRuleTest.php | 9 +++++++++ .../AllowComparingOnlyComparableTypesRule/code.php | 2 +- .../data/ForbidVariableTypeOverwritingRule/code.php | 10 +++++----- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/Rule/ForbidNotNormalizedTypeRuleTest.php b/tests/Rule/ForbidNotNormalizedTypeRuleTest.php index c63578c..2fcfcad 100644 --- a/tests/Rule/ForbidNotNormalizedTypeRuleTest.php +++ b/tests/Rule/ForbidNotNormalizedTypeRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\PhpDoc\TypeNodeResolver; use PHPStan\Type\FileTypeMapper; use ShipMonk\PHPStan\RuleTestCase; +use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -25,6 +26,10 @@ protected function getRule(): ForbidNotNormalizedTypeRule public function testRule(): void { + if (PHP_VERSION_ID < 8_02_00) { + self::markTestSkipped('Test is for PHP 8.2+, we are using native true type there'); + } + $this->analyseFile(__DIR__ . '/data/ForbidNotNormalizedTypeRule/code.php'); } diff --git a/tests/Rule/ForbidUnsafeArrayKeyRuleTest.php b/tests/Rule/ForbidUnsafeArrayKeyRuleTest.php index 2f303c0..ca27bfb 100644 --- a/tests/Rule/ForbidUnsafeArrayKeyRuleTest.php +++ b/tests/Rule/ForbidUnsafeArrayKeyRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Rules\Rule; use ShipMonk\PHPStan\Rule\ForbidUnsafeArrayKeyRule; use ShipMonk\PHPStan\RuleTestCase; +use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -35,6 +36,10 @@ protected function getRule(): Rule public function testStrict(): void { + if (PHP_VERSION_ID < 8_00_00) { + self::markTestSkipped('Test is for PHP 8.0+, we are using native mixed type there'); + } + $this->checkMixed = true; $this->checkInsideIsset = true; $this->analyseFile(__DIR__ . '/data/ForbidUnsafeArrayKeyRule/default.php'); @@ -42,6 +47,10 @@ public function testStrict(): void public function testLessStrict(): void { + if (PHP_VERSION_ID < 8_00_00) { + self::markTestSkipped('Test is for PHP 8.0+, we are using native mixed type there'); + } + $this->checkMixed = false; $this->checkInsideIsset = false; $this->analyseFile(__DIR__ . '/data/ForbidUnsafeArrayKeyRule/less-strict.php'); diff --git a/tests/Rule/data/AllowComparingOnlyComparableTypesRule/code.php b/tests/Rule/data/AllowComparingOnlyComparableTypesRule/code.php index 32148c0..8a560b0 100644 --- a/tests/Rule/data/AllowComparingOnlyComparableTypesRule/code.php +++ b/tests/Rule/data/AllowComparingOnlyComparableTypesRule/code.php @@ -25,7 +25,7 @@ interface Bar {} int|float $intOrFloat, float $float, bool $bool, - mixed $mixed, + $mixed, ) { $foos > $foo; // error: Comparison array > AllowComparingOnlyComparableTypesRule\Foo contains non-comparable type, only int|float|string|DateTimeInterface or comparable tuple is allowed. $nullableInt > $int; // error: Comparison int|null > int contains non-comparable type, only int|float|string|DateTimeInterface or comparable tuple is allowed. diff --git a/tests/Rule/data/ForbidVariableTypeOverwritingRule/code.php b/tests/Rule/data/ForbidVariableTypeOverwritingRule/code.php index 64fd193..9131f2b 100644 --- a/tests/Rule/data/ForbidVariableTypeOverwritingRule/code.php +++ b/tests/Rule/data/ForbidVariableTypeOverwritingRule/code.php @@ -74,10 +74,10 @@ function testBasics( } function testIgnoredTypes( - mixed $mixed1, - mixed $mixed2, - mixed $mixed3, - mixed $mixed4, + $mixed1, + $mixed2, + $mixed3, + $mixed4, ?ParentClass $parentClass1, ParentClass $parentClass2, ): void { @@ -103,7 +103,7 @@ function testIgnoredTypes( function testAdvancedTypesAreIgnored( array $nonEmptyArray, array $intList, - mixed $mixed, + $mixed, int $int, int $positiveInt, int $intMask,