diff --git a/build/PHPStan/Build/AttributeNamedArgumentsRule.php b/build/PHPStan/Build/AttributeNamedArgumentsRule.php index 1ff8295289..fe520d007e 100644 --- a/build/PHPStan/Build/AttributeNamedArgumentsRule.php +++ b/build/PHPStan/Build/AttributeNamedArgumentsRule.php @@ -39,6 +39,10 @@ public function processNode(Node $node, Scope $scope): array return []; } $constructor = $attributeReflection->getConstructor(); + if (!$constructor->acceptsNamedArguments()->yes()) { + return []; + } + $variants = $constructor->getVariants(); if (count($variants) !== 1) { return []; diff --git a/build/PHPStan/Build/SkipTestsWithRequiresPhpAttributeRule.php b/build/PHPStan/Build/SkipTestsWithRequiresPhpAttributeRule.php new file mode 100644 index 0000000000..00ea26f827 --- /dev/null +++ b/build/PHPStan/Build/SkipTestsWithRequiresPhpAttributeRule.php @@ -0,0 +1,130 @@ + + */ +final class SkipTestsWithRequiresPhpAttributeRule implements Rule +{ + + public function getNodeType(): string + { + return InClassMethodNode::class; + } + + public function processNode(Node $node, Scope $scope): array + { + $methodReflection = $node->getMethodReflection(); + if (!$methodReflection->getDeclaringClass()->is(TestCase::class)) { + return []; + } + + $originalNode = $node->getOriginalNode(); + if ($originalNode->stmts === null) { + return []; + } + + if (count($originalNode->stmts) === 0) { + return []; + } + + $firstStmt = $originalNode->stmts[0]; + if (!$firstStmt instanceof Node\Stmt\If_) { + return []; + } + + if (!$firstStmt->cond instanceof Node\Expr\BinaryOp) { + return []; + } + + switch (get_class($firstStmt->cond)) { + case Node\Expr\BinaryOp\SmallerOrEqual::class: + $inverseBinaryOpSigil = '>'; + break; + case Node\Expr\BinaryOp\Smaller::class: + $inverseBinaryOpSigil = '>='; + break; + case Node\Expr\BinaryOp\GreaterOrEqual::class: + $inverseBinaryOpSigil = '<'; + break; + case Node\Expr\BinaryOp\Greater::class: + $inverseBinaryOpSigil = '<='; + break; + case Node\Expr\BinaryOp\Identical::class: + $inverseBinaryOpSigil = '!=='; + break; + case Node\Expr\BinaryOp\NotIdentical::class: + $inverseBinaryOpSigil = '==='; + break; + default: + throw new ShouldNotHappenException('No inverse comparison specified for ' . get_class($firstStmt->cond)); + } + + if (!$firstStmt->cond->left instanceof Node\Expr\ConstFetch || $firstStmt->cond->left->name->toString() !== 'PHP_VERSION_ID') { + return []; + } + + if (!$firstStmt->cond->right instanceof Node\Scalar\Int_) { + return []; + } + + if (count($firstStmt->stmts) !== 1) { + return []; + } + + $ifStmt = $firstStmt->stmts[0]; + if (!$ifStmt instanceof Node\Stmt\Expression) { + return []; + } + + if (!$ifStmt->expr instanceof Node\Expr\StaticCall && !$ifStmt->expr instanceof Node\Expr\MethodCall) { + return []; + } + + if (!$ifStmt->expr->name instanceof Node\Identifier || $ifStmt->expr->name->toLowerString() !== 'marktestskipped') { + return []; + } + + $phpVersion = new PhpVersion($firstStmt->cond->right->value); + + return [ + RuleErrorBuilder::message('Skip tests with #[RequiresPhp] attribute intead.') + ->identifier('phpstan.skipTestsRequiresPhp') + ->line($firstStmt->getStartLine()) + ->fixNode($originalNode, static function (Node\Stmt\ClassMethod $node) use ($phpVersion, $inverseBinaryOpSigil) { + $stmts = $node->stmts; + if ($stmts === null) { + return $node; + } + + unset($stmts[0]); + $node->stmts = array_values($stmts); + $node->attrGroups[] = new Node\AttributeGroup([ + new Attribute(new Node\Name\FullyQualified('PHPUnit\\Framework\\Attributes\\RequiresPhp'), [ + new Node\Arg(new Node\Scalar\String_(sprintf('%s %s', $inverseBinaryOpSigil, $phpVersion->getVersionString()))), + ]), + ]); + + return $node; + }) + ->build(), + ]; + } + + +} diff --git a/build/phpstan.neon b/build/phpstan.neon index ef5c4e623b..9fbb0126bd 100644 --- a/build/phpstan.neon +++ b/build/phpstan.neon @@ -122,6 +122,7 @@ rules: - PHPStan\Build\AttributeNamedArgumentsRule - PHPStan\Build\NamedArgumentsRule - PHPStan\Build\OverrideAttributeThirdPartyMethodRule + - PHPStan\Build\SkipTestsWithRequiresPhpAttributeRule services: - diff --git a/compiler/composer.json b/compiler/composer.json index b75d11494f..5e578cc57d 100644 --- a/compiler/composer.json +++ b/compiler/composer.json @@ -6,7 +6,7 @@ "require": { "php": "^8.0", "nette/neon": "^3.0.0", - "ondrejmirtes/simple-downgrader": "^2.1.7", + "ondrejmirtes/simple-downgrader": "^2.1.8", "seld/phar-utils": "^1.2", "symfony/console": "^5.4.43", "symfony/filesystem": "^5.4.43", diff --git a/compiler/composer.lock b/compiler/composer.lock index 940847e80a..bfdad6d22c 100644 --- a/compiler/composer.lock +++ b/compiler/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": "2ba10cf4667614eb8fc8e210c6d791ff", + "content-hash": "4fa60d8069185677658793b274897b29", "packages": [ { "name": "jetbrains/phpstorm-stubs", @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/JetBrains/phpstorm-stubs.git", - "reference": "0dd20984fb84cfc157f0ef46f6e9e5b5477b8c20" + "reference": "ac36fd20eeaabc0284dff89d18f5d2862d137eb0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/JetBrains/phpstorm-stubs/zipball/0dd20984fb84cfc157f0ef46f6e9e5b5477b8c20", - "reference": "0dd20984fb84cfc157f0ef46f6e9e5b5477b8c20", + "url": "https://api.github.com/repos/JetBrains/phpstorm-stubs/zipball/ac36fd20eeaabc0284dff89d18f5d2862d137eb0", + "reference": "ac36fd20eeaabc0284dff89d18f5d2862d137eb0", "shasum": "" }, "require-dev": { @@ -52,7 +52,7 @@ "support": { "source": "https://github.com/JetBrains/phpstorm-stubs/tree/master" }, - "time": "2025-05-21T19:01:16+00:00" + "time": "2025-06-03T13:57:24+00:00" }, { "name": "nette/neon", @@ -339,16 +339,16 @@ }, { "name": "ondrejmirtes/simple-downgrader", - "version": "2.1.7", + "version": "2.1.8", "source": { "type": "git", "url": "https://github.com/ondrejmirtes/simple-downgrader.git", - "reference": "c73a88c7d26ea9e5f0662b9587e7282a9c34c96b" + "reference": "d06358fee2f120c74b41f8c1f8b1f205e2b579c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ondrejmirtes/simple-downgrader/zipball/c73a88c7d26ea9e5f0662b9587e7282a9c34c96b", - "reference": "c73a88c7d26ea9e5f0662b9587e7282a9c34c96b", + "url": "https://api.github.com/repos/ondrejmirtes/simple-downgrader/zipball/d06358fee2f120c74b41f8c1f8b1f205e2b579c6", + "reference": "d06358fee2f120c74b41f8c1f8b1f205e2b579c6", "shasum": "" }, "require": { @@ -384,9 +384,9 @@ "description": "Simple Downgrader", "support": { "issues": "https://github.com/ondrejmirtes/simple-downgrader/issues", - "source": "https://github.com/ondrejmirtes/simple-downgrader/tree/2.1.7" + "source": "https://github.com/ondrejmirtes/simple-downgrader/tree/2.1.8" }, - "time": "2025-06-03T13:58:28+00:00" + "time": "2025-06-10T08:25:55+00:00" }, { "name": "phpstan/phpdoc-parser", diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index a611443139..975145dea2 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -11,6 +11,7 @@ use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; +use PHPUnit\Framework\Attributes\RequiresPhp; use function extension_loaded; use function restore_error_handler; use function sprintf; @@ -323,12 +324,9 @@ public function testBug11649(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug6872(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-6872.php'); $this->assertNoErrors($errors); } @@ -448,12 +446,9 @@ public function testBug5231Two(): void $this->assertNotEmpty($errors); } + #[RequiresPhp('>= 8.1')] public function testBug12512(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-12512.php'); $this->assertNoErrors($errors); } @@ -482,21 +477,16 @@ public function testBug5657(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug5951(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } $errors = $this->runAnalyse(__DIR__ . '/data/bug-5951.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/enums-integration.php'); $this->assertCount(3, $errors); $this->assertSame('Access to an undefined property EnumIntegrationTest\Foo::TWO::$value.', $errors[0]->getMessage()); @@ -527,11 +517,9 @@ public function testBug6466(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testBug6494(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $errors = $this->runAnalyse(__DIR__ . '/data/bug-6494.php'); $this->assertNoErrors($errors); } @@ -579,12 +567,9 @@ public function testBug6501(): void $this->assertSame(24, $errors[0]->getLine()); } + #[RequiresPhp('>= 8.0')] public function testBug6114(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-6114.php'); $this->assertNoErrors($errors); } @@ -636,12 +621,9 @@ public function testBug6842(): void $this->assertSame(54, $errors[1]->getLine()); } + #[RequiresPhp('>= 8.0')] public function testBug6896(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-6896.php'); $this->assertCount(4, $errors); $this->assertSame('Generic type IteratorIterator<(int|string), mixed> in PHPDoc tag @return does not specify all template types of class IteratorIterator: TKey, TValue, TIterator', $errors[0]->getMessage()); @@ -680,12 +662,9 @@ public function testBug1388(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug4308(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-4308.php'); $this->assertNoErrors($errors); } @@ -720,22 +699,16 @@ public function testBug7030(): void null, $shippingLongitude = null, $shippingNeutralShipping = null)): Unexpected token "\n * ", expected type at offset 193 on line 6', $errors[0]->getMessage()); } + #[RequiresPhp('>= 8.1')] public function testBug7012(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-7012.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testBug6192(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-6192.php'); $this->assertNoErrors($errors); } @@ -746,12 +719,9 @@ public function testBug7068(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testDiscussion6993(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/nsrt/bug-6993.php'); $this->assertCount(1, $errors); $this->assertSame('Parameter #1 $specificable of method Bug6993\AndSpecificationValidator::isSatisfiedBy() expects Bug6993\Foo, Bug6993\Bar given.', $errors[0]->getMessage()); @@ -763,22 +733,16 @@ public function testBug7077(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug7078(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/nsrt/bug-7078.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug7116(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-7116.php'); $this->assertNoErrors($errors); } @@ -789,23 +753,17 @@ public function testBug3853(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testBug7135(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-7135.php'); $this->assertCount(1, $errors); $this->assertSame('Cannot create callable from the new operator.', $errors[0]->getMessage()); } + #[RequiresPhp('>= 8.0')] public function testDiscussion7124(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/discussion-7124.php'); $this->assertCount(4, $errors); $this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, 0|1|2=): bool, Closure(int, bool): bool given.', $errors[0]->getMessage()); @@ -861,12 +819,9 @@ public function testBug7094(): void $this->assertSame(29, $errors[5]->getLine()); } + #[RequiresPhp('>= 8.0')] public function testOffsetAccess(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/nsrt/offset-access.php'); $this->assertCount(1, $errors); $this->assertSame('PHPDoc tag @return contains unresolvable type.', $errors[0]->getMessage()); @@ -1050,22 +1005,16 @@ public function testBug7963Two(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testBug8078(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-8078.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testBug8072(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-8072.php'); $this->assertNoErrors($errors); } @@ -1123,12 +1072,9 @@ public function testBug8376(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testAssertDocblock(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/nsrt/assert-docblock.php'); $this->assertCount(4, $errors); $this->assertSame('Call to method AssertDocblock\A::testInt() with string will always evaluate to false.', $errors[0]->getMessage()); @@ -1141,22 +1087,16 @@ public function testAssertDocblock(): void $this->assertSame(238, $errors[3]->getLine()); } + #[RequiresPhp('>= 8.0')] public function testBug8147(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-8147.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug12934(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-12934.php'); $this->assertNoErrors($errors); } @@ -1185,12 +1125,9 @@ public function testBug8503(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug8537(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-8537.php'); $this->assertNoErrors($errors); } @@ -1238,12 +1175,9 @@ public function testSkipCheckNoGenericClasses(): void $this->assertSame('Method SkipCheckNoGenericClasses\Foo::doFoo() has parameter $i with generic class LimitIterator but does not specify its types: TKey, TValue, TIterator', $errors[0]->getMessage()); } + #[RequiresPhp('>= 8.1')] public function testBug8983(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-8983.php'); $this->assertNoErrors($errors); } @@ -1280,12 +1214,9 @@ public function testBug9039(): void $this->assertSame('Constant Bug9039\Test::RULES is unused.', $errors[0]->getMessage()); } + #[RequiresPhp('>= 8.0')] public function testDiscussion9053(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/discussion-9053.php'); $this->assertNoErrors($errors); } @@ -1296,12 +1227,9 @@ public function testProcessCalledMethodInfiniteLoop(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug9428(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-9428.php'); $this->assertNoErrors($errors); } @@ -1333,34 +1261,25 @@ public function testIgnoreIdentifiers(): void $this->assertSame(16, $errors[4]->getLine()); } + #[RequiresPhp('>= 8.1')] public function testBug9994(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-9994.php'); $this->assertCount(2, $errors); $this->assertSame('Negated boolean expression is always false.', $errors[0]->getMessage()); $this->assertSame('Parameter #2 $callback of function array_filter expects (callable(1|2|3|null): bool)|null, false given.', $errors[1]->getMessage()); } + #[RequiresPhp('>= 8.1')] public function testBug10049(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-10049-recursive.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug10086(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-10086.php'); $this->assertNoErrors($errors); } @@ -1371,12 +1290,9 @@ public function testBug10147(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.2')] public function testBug10302(): void { - if (PHP_VERSION_ID < 80200) { - $this->markTestSkipped('Test requires PHP 8.2'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-10302.php'); $this->assertNoErrors($errors); } @@ -1403,42 +1319,30 @@ public function testBug10538(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testBug10847(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-10847.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testBug10772(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-10772.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testBug10985(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-10985.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testBug10979(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-10979.php'); $this->assertNoErrors($errors); } @@ -1455,33 +1359,24 @@ public function testBug10867(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testBug11263(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-11263.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug11147(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-11147.php'); $this->assertCount(1, $errors); $this->assertSame('Method Bug11147\RedisAdapter::createConnection() has invalid return type Bug11147\NonExistentClass.', $errors[0]->getMessage()); } + #[RequiresPhp('>= 8.0')] public function testBug11283(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-11283.php'); $this->assertNoErrors($errors); } @@ -1492,32 +1387,23 @@ public function testBug11292(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testBug11297(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-11297.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug5597(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-5597.php'); $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug11511(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-11511.php'); $this->assertCount(1, $errors); $this->assertSame('Access to an undefined property object::$bar.', $errors[0]->getMessage()); @@ -1535,12 +1421,9 @@ public function testBug11640(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.0')] public function testBug11709(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-11709.php'); $this->assertNoErrors($errors); } @@ -1551,12 +1434,9 @@ public function testBug11913(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.3')] public function testBug12549(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-12549.php'); $this->assertNoErrors($errors); } @@ -1567,12 +1447,9 @@ public function testBug12627(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.3')] public function testBug12159(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-12159.php'); $this->assertNoErrors($errors); } @@ -1589,13 +1466,9 @@ public function testBug12800(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.3')] public function testBug12949(): void { - // Fetching class constants with a dynamic name is supported only on PHP 8.3 and later - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $errors = $this->runAnalyse(__DIR__ . '/data/bug-12949.php'); $this->assertCount(3, $errors); $this->assertSame('Call to an undefined method object::0().', $errors[0]->getMessage()); diff --git a/tests/PHPStan/Analyser/AnalyserTest.php b/tests/PHPStan/Analyser/AnalyserTest.php index 9348cd7b73..51f95f9c47 100644 --- a/tests/PHPStan/Analyser/AnalyserTest.php +++ b/tests/PHPStan/Analyser/AnalyserTest.php @@ -30,6 +30,7 @@ use PHPStan\Rules\Properties\ReadWritePropertiesExtensionProvider; use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\FileTypeMapper; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use function array_map; use function array_merge; @@ -195,9 +196,9 @@ public static function dataIgnoreErrorByPathAndCount(): iterable } /** - * @dataProvider dataIgnoreErrorByPathAndCount * @param mixed[] $ignoreErrors */ + #[DataProvider('dataIgnoreErrorByPathAndCount')] public function testIgnoreErrorByPathAndCount(array $ignoreErrors): void { $result = $this->runAnalyser($ignoreErrors, true, __DIR__ . '/data/two-fails.php', false); @@ -212,9 +213,7 @@ public static function dataTrueAndFalse(): array ]; } - /** - * @dataProvider dataTrueAndFalse - */ + #[DataProvider('dataTrueAndFalse')] public function testIgnoreErrorByPathAndIdentifierCountsCorrectly(bool $onlyFiles): void { $ignoreErrors = [ @@ -238,9 +237,7 @@ public function testIgnoreErrorByPathAndIdentifierCountsCorrectly(bool $onlyFile $this->assertNoErrors($result); } - /** - * @dataProvider dataTrueAndFalse - */ + #[DataProvider('dataTrueAndFalse')] public function testIgnoreErrorByPathAndCountMoreThanExpected(bool $onlyFiles): void { $ignoreErrors = [ @@ -269,9 +266,7 @@ public function testIgnoreErrorByPathAndCountMoreThanExpected(bool $onlyFiles): $this->assertSamePaths(__DIR__ . '/data/two-fails.php', $result[2]->getFile()); } - /** - * @dataProvider dataTrueAndFalse - */ + #[DataProvider('dataTrueAndFalse')] public function testIgnoreErrorByPathAndCountLessThanExpected(bool $onlyFiles): void { $ignoreErrors = [ @@ -434,9 +429,7 @@ public static function dataIgnoreErrorInTraitUsingClassFilePath(): array ]; } - /** - * @dataProvider dataIgnoreErrorInTraitUsingClassFilePath - */ + #[DataProvider('dataIgnoreErrorInTraitUsingClassFilePath')] public function testIgnoreErrorInTraitUsingClassFilePath(string $pathToIgnore): void { $ignoreErrors = [ @@ -487,9 +480,7 @@ public function testReportMultipleParserErrorsAtOnce(): void $this->assertSame(10, $errorTwo->getLine()); } - /** - * @dataProvider dataTrueAndFalse - */ + #[DataProvider('dataTrueAndFalse')] public function testDoNotReportUnmatchedIgnoredErrorsFromPathIfPathWasNotAnalysed(bool $onlyFiles): void { $ignoreErrors = [ @@ -508,9 +499,7 @@ public function testDoNotReportUnmatchedIgnoredErrorsFromPathIfPathWasNotAnalyse $this->assertNoErrors($result); } - /** - * @dataProvider dataTrueAndFalse - */ + #[DataProvider('dataTrueAndFalse')] public function testDoNotReportUnmatchedIgnoredErrorsFromPathWithCountIfPathWasNotAnalysed(bool $onlyFiles): void { $ignoreErrors = [ @@ -559,9 +548,7 @@ public function testIgnoreNextLineUnmatched(): void } } - /** - * @dataProvider dataTrueAndFalse - */ + #[DataProvider('dataTrueAndFalse')] public function testIgnoreLine(bool $reportUnmatchedIgnoredErrors): void { $result = $this->runAnalyser([], $reportUnmatchedIgnoredErrors, [ diff --git a/tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php index d7bf6a1ba1..914064439f 100644 --- a/tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php @@ -5,12 +5,12 @@ use Override; use PHPStan\File\FileHelper; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_map; use function array_merge; use function array_unique; use function sprintf; use function usort; -use const PHP_VERSION_ID; class AnalyserTraitsIntegrationTest extends PHPStanTestCase { @@ -171,12 +171,9 @@ public function testMissingReturnInAbstractTraitMethod(): void $this->assertNoErrors($errors); } + #[RequiresPhp('>= 8.1')] public function testUnititializedReadonlyPropertyAccessedInTrait(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped(); - } - $errors = $this->runAnalyse([ __DIR__ . '/traits/uninitializedProperty/FooClass.php', __DIR__ . '/traits/uninitializedProperty/FooTrait.php', diff --git a/tests/PHPStan/Analyser/ArgumentsNormalizerLegacyTest.php b/tests/PHPStan/Analyser/ArgumentsNormalizerLegacyTest.php index 34b7c46232..9b92249486 100644 --- a/tests/PHPStan/Analyser/ArgumentsNormalizerLegacyTest.php +++ b/tests/PHPStan/Analyser/ArgumentsNormalizerLegacyTest.php @@ -13,7 +13,7 @@ use PHPStan\ShouldNotHappenException; use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\Constant\ConstantIntegerType; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; final class ArgumentsNormalizerLegacyTest extends PHPStanTestCase { @@ -21,12 +21,9 @@ final class ArgumentsNormalizerLegacyTest extends PHPStanTestCase /** * function call, all arguments named and given in order */ + #[RequiresPhp('>= 8.0')] public function testArgumentReorderAllNamed(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $funcName = new Name('json_encode'); $reflectionProvider = self::getContainer()->getByType(NativeFunctionReflectionProvider::class); $functionReflection = $reflectionProvider->findFunctionReflection('json_encode'); @@ -65,12 +62,9 @@ public function testArgumentReorderAllNamed(): void /** * function call, all args named, not in order */ + #[RequiresPhp('>= 8.0')] public function testArgumentReorderAllNamedWithSkipped(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $funcName = new Name('json_encode'); $reflectionProvider = self::getContainer()->getByType(NativeFunctionReflectionProvider::class); $functionReflection = $reflectionProvider->findFunctionReflection('json_encode'); @@ -112,12 +106,9 @@ public function testArgumentReorderAllNamedWithSkipped(): void $this->assertSame(128, $reorderedArgs[2]->value->value); } + #[RequiresPhp('>= 8.0')] public function testMissingRequiredParameter(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $funcName = new Name('json_encode'); $reflectionProvider = self::getContainer()->getByType(NativeFunctionReflectionProvider::class); $functionReflection = $reflectionProvider->findFunctionReflection('json_encode'); diff --git a/tests/PHPStan/Analyser/ArgumentsNormalizerTest.php b/tests/PHPStan/Analyser/ArgumentsNormalizerTest.php index 184d3aba8c..b2cc10be5d 100644 --- a/tests/PHPStan/Analyser/ArgumentsNormalizerTest.php +++ b/tests/PHPStan/Analyser/ArgumentsNormalizerTest.php @@ -17,6 +17,7 @@ use PHPStan\Type\StringType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function count; class ArgumentsNormalizerTest extends PHPStanTestCase @@ -245,11 +246,11 @@ public static function dataReorderValid(): iterable } /** - * @dataProvider dataReorderValid * @param array $parameterSettings * @param array $argumentSettings * @param array $expectedArgumentTypes */ + #[DataProvider('dataReorderValid')] public function testReorderValid( array $parameterSettings, array $argumentSettings, @@ -325,10 +326,10 @@ public static function dataReorderInvalid(): iterable } /** - * @dataProvider dataReorderInvalid * @param array $parameterSettings * @param array $argumentSettings */ + #[DataProvider('dataReorderInvalid')] public function testReorderInvalid( array $parameterSettings, array $argumentSettings, diff --git a/tests/PHPStan/Analyser/AssertStubTest.php b/tests/PHPStan/Analyser/AssertStubTest.php index b4df473245..579e52e359 100644 --- a/tests/PHPStan/Analyser/AssertStubTest.php +++ b/tests/PHPStan/Analyser/AssertStubTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class AssertStubTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/Bug10922Test.php b/tests/PHPStan/Analyser/Bug10922Test.php index d1a27e11c8..6fa62ea5e7 100644 --- a/tests/PHPStan/Analyser/Bug10922Test.php +++ b/tests/PHPStan/Analyser/Bug10922Test.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class Bug10922Test extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/Bug10980Test.php b/tests/PHPStan/Analyser/Bug10980Test.php index fc7bea417c..51422dcd45 100644 --- a/tests/PHPStan/Analyser/Bug10980Test.php +++ b/tests/PHPStan/Analyser/Bug10980Test.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class Bug10980Test extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/Bug11009Test.php b/tests/PHPStan/Analyser/Bug11009Test.php index 23a3c0b256..d558eb0a0f 100644 --- a/tests/PHPStan/Analyser/Bug11009Test.php +++ b/tests/PHPStan/Analyser/Bug11009Test.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class Bug11009Test extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/Bug9307Test.php b/tests/PHPStan/Analyser/Bug9307Test.php index f1dcf78745..1de98619ea 100644 --- a/tests/PHPStan/Analyser/Bug9307Test.php +++ b/tests/PHPStan/Analyser/Bug9307Test.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class Bug9307Test extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/ClassConstantStubFileTest.php b/tests/PHPStan/Analyser/ClassConstantStubFileTest.php index a2f8930f99..2d1cb36f58 100644 --- a/tests/PHPStan/Analyser/ClassConstantStubFileTest.php +++ b/tests/PHPStan/Analyser/ClassConstantStubFileTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ClassConstantStubFileTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/ConditionalReturnTypeFromMethodStubTest.php b/tests/PHPStan/Analyser/ConditionalReturnTypeFromMethodStubTest.php index 97a3683dd4..af19568166 100644 --- a/tests/PHPStan/Analyser/ConditionalReturnTypeFromMethodStubTest.php +++ b/tests/PHPStan/Analyser/ConditionalReturnTypeFromMethodStubTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ConditionalReturnTypeFromMethodStubTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/DoNotPolluteScopeWithBlockTest.php b/tests/PHPStan/Analyser/DoNotPolluteScopeWithBlockTest.php index 4e2e6063e0..8b94d130e0 100644 --- a/tests/PHPStan/Analyser/DoNotPolluteScopeWithBlockTest.php +++ b/tests/PHPStan/Analyser/DoNotPolluteScopeWithBlockTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class DoNotPolluteScopeWithBlockTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/DoNotRememberPossiblyImpureFunctionValuesTest.php b/tests/PHPStan/Analyser/DoNotRememberPossiblyImpureFunctionValuesTest.php index 9ed49ed42b..75a9797ee3 100644 --- a/tests/PHPStan/Analyser/DoNotRememberPossiblyImpureFunctionValuesTest.php +++ b/tests/PHPStan/Analyser/DoNotRememberPossiblyImpureFunctionValuesTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class DoNotRememberPossiblyImpureFunctionValuesTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataAsserts(): iterable } /** - * @dataProvider dataAsserts * @param mixed ...$args */ + #[DataProvider('dataAsserts')] public function testAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/DynamicMethodThrowTypeExtensionTest.php b/tests/PHPStan/Analyser/DynamicMethodThrowTypeExtensionTest.php index 9ae0f4ad22..9a55ab9360 100644 --- a/tests/PHPStan/Analyser/DynamicMethodThrowTypeExtensionTest.php +++ b/tests/PHPStan/Analyser/DynamicMethodThrowTypeExtensionTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use const PHP_VERSION_ID; class DynamicMethodThrowTypeExtensionTest extends TypeInferenceTestCase @@ -19,9 +20,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/DynamicReturnTypeExtensionTypeInferenceTest.php b/tests/PHPStan/Analyser/DynamicReturnTypeExtensionTypeInferenceTest.php index 481a6c24ca..d336534264 100644 --- a/tests/PHPStan/Analyser/DynamicReturnTypeExtensionTypeInferenceTest.php +++ b/tests/PHPStan/Analyser/DynamicReturnTypeExtensionTypeInferenceTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use const PHP_VERSION_ID; class DynamicReturnTypeExtensionTypeInferenceTest extends TypeInferenceTestCase @@ -22,9 +23,9 @@ public static function dataAsserts(): iterable } /** - * @dataProvider dataAsserts * @param mixed ...$args */ + #[DataProvider('dataAsserts')] public function testAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/ErrorTest.php b/tests/PHPStan/Analyser/ErrorTest.php index 0ec0b8bf36..e59abafff3 100644 --- a/tests/PHPStan/Analyser/ErrorTest.php +++ b/tests/PHPStan/Analyser/ErrorTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ErrorTest extends PHPStanTestCase { @@ -29,9 +30,7 @@ public static function dataValidIdentifier(): iterable yield ['3m.blah']; } - /** - * @dataProvider dataValidIdentifier - */ + #[DataProvider('dataValidIdentifier')] public function testValidIdentifier(string $identifier): void { $this->assertTrue(Error::validateIdentifier($identifier)); @@ -48,9 +47,7 @@ public static function dataInvalidIdentifier(): iterable yield ['.']; } - /** - * @dataProvider dataInvalidIdentifier - */ + #[DataProvider('dataInvalidIdentifier')] public function testInvalidIdentifier(string $identifier): void { $this->assertFalse(Error::validateIdentifier($identifier)); diff --git a/tests/PHPStan/Analyser/ExpressionTypeResolverExtensionTest.php b/tests/PHPStan/Analyser/ExpressionTypeResolverExtensionTest.php index 22169d7158..6c3d707942 100644 --- a/tests/PHPStan/Analyser/ExpressionTypeResolverExtensionTest.php +++ b/tests/PHPStan/Analyser/ExpressionTypeResolverExtensionTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ExpressionTypeResolverExtensionTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/Ignore/IgnoreLexerTest.php b/tests/PHPStan/Analyser/Ignore/IgnoreLexerTest.php index f4aa27f5c3..6e46630df6 100644 --- a/tests/PHPStan/Analyser/Ignore/IgnoreLexerTest.php +++ b/tests/PHPStan/Analyser/Ignore/IgnoreLexerTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser\Ignore; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function array_pop; use function substr_count; use const PHP_EOL; @@ -80,9 +81,9 @@ public static function dataTokenize(): iterable } /** - * @dataProvider dataTokenize * @param list $expectedTokens */ + #[DataProvider('dataTokenize')] public function testTokenize(string $input, array $expectedTokens): void { $lexer = new IgnoreLexer(); diff --git a/tests/PHPStan/Analyser/ImmediatelyCalledFunctionWithoutImplicitThrowTest.php b/tests/PHPStan/Analyser/ImmediatelyCalledFunctionWithoutImplicitThrowTest.php index b182b1bea4..8a9e2ee7a6 100644 --- a/tests/PHPStan/Analyser/ImmediatelyCalledFunctionWithoutImplicitThrowTest.php +++ b/tests/PHPStan/Analyser/ImmediatelyCalledFunctionWithoutImplicitThrowTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function array_merge; class ImmediatelyCalledFunctionWithoutImplicitThrowTest extends TypeInferenceTestCase @@ -14,9 +15,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/InstanceMethodsParameterScopeFunctionTest.php b/tests/PHPStan/Analyser/InstanceMethodsParameterScopeFunctionTest.php index 7cbae1c8be..ea3288772f 100644 --- a/tests/PHPStan/Analyser/InstanceMethodsParameterScopeFunctionTest.php +++ b/tests/PHPStan/Analyser/InstanceMethodsParameterScopeFunctionTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -22,12 +22,9 @@ protected function shouldNarrowMethodScopeFromConstructor(): bool return true; } + #[RequiresPhp('>= 8.0')] public function testRule(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/instance-methods-parameter-scope.php'], [ [ 'Name DateTime found in function scope null', diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index ba4c419352..8163ab9a81 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -16,6 +16,8 @@ use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use SomeNodeScopeResolverNamespace\Foo; use function define; use function defined; @@ -88,9 +90,7 @@ public static function dataUnionInCatch(): array ]; } - /** - * @dataProvider dataUnionInCatch - */ + #[DataProvider('dataUnionInCatch')] public function testUnionInCatch( string $description, string $expression, @@ -213,9 +213,7 @@ public static function dataUnionAndIntersection(): array ]; } - /** - * @dataProvider dataUnionAndIntersection - */ + #[DataProvider('dataUnionAndIntersection')] public function testUnionAndIntersection( string $description, string $expression, @@ -738,9 +736,7 @@ public static function dataAssignInIf(): array ]; } - /** - * @dataProvider dataAssignInIf - */ + #[DataProvider('dataAssignInIf')] public function testAssignInIf( Scope $scope, string $variableName, @@ -876,9 +872,7 @@ public static function dataConstantTypes(): array ]; } - /** - * @dataProvider dataConstantTypes - */ + #[DataProvider('dataConstantTypes')] public function testConstantTypes( Scope $scope, string $variableName, @@ -1211,9 +1205,7 @@ public static function dataArrayDestructuring(): array ]; } - /** - * @dataProvider dataArrayDestructuring - */ + #[DataProvider('dataArrayDestructuring')] public function testArrayDestructuring( string $description, string $expression, @@ -1292,9 +1284,7 @@ public static function dataParameterTypes(): array ]; } - /** - * @dataProvider dataParameterTypes - */ + #[DataProvider('dataParameterTypes')] public function testTypehints( string $typeClass, string $expression, @@ -1353,9 +1343,7 @@ public static function dataAnonymousFunctionParameterTypes(): array ]; } - /** - * @dataProvider dataAnonymousFunctionParameterTypes - */ + #[DataProvider('dataAnonymousFunctionParameterTypes')] public function testAnonymousFunctionTypehints( string $description, string $expression, @@ -1434,9 +1422,7 @@ public static function dataVarAnnotations(): array ]; } - /** - * @dataProvider dataVarAnnotations - */ + #[DataProvider('dataVarAnnotations')] public function testVarAnnotations( string $description, string $expression, @@ -1590,9 +1576,7 @@ public static function dataCasts(): array ]; } - /** - * @dataProvider dataCasts - */ + #[DataProvider('dataCasts')] public function testCasts( string $desciptiion, string $expression, @@ -1719,9 +1703,7 @@ public static function dataDeductedTypes(): array ]; } - /** - * @dataProvider dataDeductedTypes - */ + #[DataProvider('dataDeductedTypes')] public function testDeductedTypes( string $description, string $expression, @@ -1865,9 +1847,7 @@ public static function dataProperties(): array ]; } - /** - * @dataProvider dataProperties - */ + #[DataProvider('dataProperties')] public function testProperties( string $description, string $expression, @@ -3182,9 +3162,7 @@ public static function dataBinaryOperations(): array ]; } - /** - * @dataProvider dataBinaryOperations - */ + #[DataProvider('dataBinaryOperations')] public function testBinaryOperations( string $description, string $expression, @@ -3207,9 +3185,7 @@ public static function dataVarStatementAnnotation(): array ]; } - /** - * @dataProvider dataVarStatementAnnotation - */ + #[DataProvider('dataVarStatementAnnotation')] public function testVarStatementAnnotation( string $description, string $expression, @@ -3232,9 +3208,7 @@ public static function dataCloneOperators(): array ]; } - /** - * @dataProvider dataCloneOperators - */ + #[DataProvider('dataCloneOperators')] public function testCloneOperators( string $description, string $expression, @@ -3285,9 +3259,7 @@ public static function dataLiteralArrays(): array ]; } - /** - * @dataProvider dataLiteralArrays - */ + #[DataProvider('dataLiteralArrays')] public function testLiteralArrays( string $description, string $expression, @@ -3362,9 +3334,7 @@ public static function dataLiteralArraysKeys(): array ]; } - /** - * @dataProvider dataLiteralArraysKeys - */ + #[DataProvider('dataLiteralArraysKeys')] public function testLiteralArraysKeys( string $description, string $evaluatedPointExpressionType, @@ -3404,9 +3374,7 @@ public static function dataStringArrayAccess(): array ]; } - /** - * @dataProvider dataStringArrayAccess - */ + #[DataProvider('dataStringArrayAccess')] public function testStringArrayAccess( string $description, string $expression, @@ -3579,10 +3547,8 @@ public static function dataTypeFromFunctionFunctionPhpDocs(): array ]; } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromFunctionFunctionPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromFunctionFunctionPhpDocs')] public function testTypeFromFunctionPhpDocs( string $description, string $expression, @@ -3606,10 +3572,8 @@ public static function dataTypeFromFunctionPrefixedPhpDocs(): array ]; } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromFunctionPrefixedPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromFunctionPrefixedPhpDocs')] public function testTypeFromFunctionPhpDocsPsalmPrefix( string $description, string $expression, @@ -3623,10 +3587,8 @@ public function testTypeFromFunctionPhpDocsPsalmPrefix( ); } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromFunctionPrefixedPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromFunctionPrefixedPhpDocs')] public function testTypeFromFunctionPhpDocsPhpstanPrefix( string $description, string $expression, @@ -3640,10 +3602,8 @@ public function testTypeFromFunctionPhpDocsPhpstanPrefix( ); } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromFunctionPrefixedPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromFunctionPrefixedPhpDocs')] public function testTypeFromFunctionPhpDocsPhanPrefix( string $description, string $expression, @@ -3799,10 +3759,8 @@ public static function dataTypeFromMethodPhpDocs(): array ]; } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromMethodPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromMethodPhpDocs')] public function testTypeFromMethodPhpDocs( string $description, string $expression, @@ -3815,10 +3773,8 @@ public function testTypeFromMethodPhpDocs( ); } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromMethodPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromMethodPhpDocs')] public function testTypeFromMethodPhpDocsPsalmPrefix( string $description, string $expression, @@ -3841,10 +3797,10 @@ public function testTypeFromMethodPhpDocsPsalmPrefix( } /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromMethodPhpDocs * @param bool $replaceClass = true */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromMethodPhpDocs')] public function testTypeFromMethodPhpDocsPhpstanPrefix( string $description, string $expression, @@ -3866,10 +3822,8 @@ public function testTypeFromMethodPhpDocsPhpstanPrefix( ); } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromMethodPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromMethodPhpDocs')] public function testTypeFromMethodPhpDocsPhanPrefix( string $description, string $expression, @@ -3891,10 +3845,8 @@ public function testTypeFromMethodPhpDocsPhanPrefix( ); } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromMethodPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromMethodPhpDocs')] public function testTypeFromTraitPhpDocs( string $description, string $expression, @@ -3916,10 +3868,8 @@ public function testTypeFromTraitPhpDocs( ); } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromMethodPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromMethodPhpDocs')] public function testTypeFromMethodPhpDocsInheritDocWithoutCurlyBraces( string $description, string $expression, @@ -3941,10 +3891,8 @@ public function testTypeFromMethodPhpDocsInheritDocWithoutCurlyBraces( ); } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromMethodPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromMethodPhpDocs')] public function testTypeFromRecursiveTraitPhpDocs( string $description, string $expression, @@ -3976,9 +3924,7 @@ public static function dataTypeFromTraitPhpDocsInSameFile(): array ]; } - /** - * @dataProvider dataTypeFromTraitPhpDocsInSameFile - */ + #[DataProvider('dataTypeFromTraitPhpDocsInSameFile')] public function testTypeFromTraitPhpDocsInSameFile( string $description, string $expression, @@ -3991,10 +3937,8 @@ public function testTypeFromTraitPhpDocsInSameFile( ); } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromMethodPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromMethodPhpDocs')] public function testTypeFromMethodPhpDocsInheritDoc( string $description, string $expression, @@ -4016,10 +3960,8 @@ public function testTypeFromMethodPhpDocsInheritDoc( ); } - /** - * @dataProvider dataTypeFromFunctionPhpDocs - * @dataProvider dataTypeFromMethodPhpDocs - */ + #[DataProvider('dataTypeFromFunctionPhpDocs')] + #[DataProvider('dataTypeFromMethodPhpDocs')] public function testTypeFromMethodPhpDocsImplicitInheritance( string $description, string $expression, @@ -4068,9 +4010,7 @@ public static function dataSwitchInstanceOf(): array ]; } - /** - * @dataProvider dataSwitchInstanceOf - */ + #[DataProvider('dataSwitchInstanceOf')] public function testSwitchInstanceof( string $description, string $expression, @@ -4083,9 +4023,7 @@ public function testSwitchInstanceof( ); } - /** - * @dataProvider dataSwitchInstanceOf - */ + #[DataProvider('dataSwitchInstanceOf')] public function testSwitchInstanceofTruthy( string $description, string $expression, @@ -4114,9 +4052,7 @@ public static function dataSwitchGetClass(): array ]; } - /** - * @dataProvider dataSwitchGetClass - */ + #[DataProvider('dataSwitchGetClass')] public function testSwitchGetClass( string $description, string $expression, @@ -4141,9 +4077,7 @@ public static function dataSwitchInstanceOfFallthrough(): array ]; } - /** - * @dataProvider dataSwitchInstanceOfFallthrough - */ + #[DataProvider('dataSwitchInstanceOfFallthrough')] public function testSwitchInstanceOfFallthrough( string $description, string $expression, @@ -4166,9 +4100,7 @@ public static function dataSwitchTypeElimination(): array ]; } - /** - * @dataProvider dataSwitchTypeElimination - */ + #[DataProvider('dataSwitchTypeElimination')] public function testSwitchTypeElimination( string $description, string $expression, @@ -4202,9 +4134,7 @@ public static function dataOverwritingVariable(): array ]; } - /** - * @dataProvider dataOverwritingVariable - */ + #[DataProvider('dataOverwritingVariable')] public function testOverwritingVariable( string $description, string $expression, @@ -4269,9 +4199,7 @@ public static function dataNegatedInstanceof(): array ]; } - /** - * @dataProvider dataNegatedInstanceof - */ + #[DataProvider('dataNegatedInstanceof')] public function testNegatedInstanceof( string $description, string $expression, @@ -4306,9 +4234,7 @@ public static function dataAnonymousFunction(): array ]; } - /** - * @dataProvider dataAnonymousFunction - */ + #[DataProvider('dataAnonymousFunction')] public function testAnonymousFunction( string $description, string $expression, @@ -4442,9 +4368,7 @@ public static function dataForeachArrayType(): array ]; } - /** - * @dataProvider dataForeachArrayType - */ + #[DataProvider('dataForeachArrayType')] public function testForeachArrayType( string $file, string $description, @@ -4469,9 +4393,7 @@ public static function dataOverridingSpecifiedType(): array ]; } - /** - * @dataProvider dataOverridingSpecifiedType - */ + #[DataProvider('dataOverridingSpecifiedType')] public function testOverridingSpecifiedType( string $file, string $description, @@ -4527,9 +4449,7 @@ public static function dataForeachObjectType(): array ]; } - /** - * @dataProvider dataForeachObjectType - */ + #[DataProvider('dataForeachObjectType')] public function testForeachObjectType( string $file, string $description, @@ -5256,9 +5176,7 @@ public static function dataArrayFunctions(): array ]; } - /** - * @dataProvider dataArrayFunctions - */ + #[DataProvider('dataArrayFunctions')] public function testArrayFunctions( string $description, string $expression, @@ -5634,9 +5552,7 @@ public static function dataFunctions(): array ]; } - /** - * @dataProvider dataFunctions - */ + #[DataProvider('dataFunctions')] public function testFunctions( string $description, string $expression, @@ -5659,9 +5575,7 @@ public static function dataDioFunctions(): array ]; } - /** - * @dataProvider dataDioFunctions - */ + #[DataProvider('dataDioFunctions')] public function testDioFunctions( string $description, string $expression, @@ -5687,9 +5601,7 @@ public static function dataSsh2Functions(): array ]; } - /** - * @dataProvider dataSsh2Functions - */ + #[DataProvider('dataSsh2Functions')] public function testSsh2Functions( string $description, string $expression, @@ -5760,9 +5672,7 @@ public static function dataRangeFunction(): array ]; } - /** - * @dataProvider dataRangeFunction - */ + #[DataProvider('dataRangeFunction')] public function testRangeFunction( string $description, string $expression, @@ -5917,9 +5827,7 @@ public static function dataSpecifiedTypesUsingIsFunctions(): array ]; } - /** - * @dataProvider dataSpecifiedTypesUsingIsFunctions - */ + #[DataProvider('dataSpecifiedTypesUsingIsFunctions')] public function testSpecifiedTypesUsingIsFunctions( string $description, string $expression, @@ -6082,9 +5990,7 @@ public static function dataIterable(): array ]; } - /** - * @dataProvider dataIterable - */ + #[DataProvider('dataIterable')] public function testIterable( string $description, string $expression, @@ -6119,9 +6025,7 @@ public static function dataArrayAccess(): array ]; } - /** - * @dataProvider dataArrayAccess - */ + #[DataProvider('dataArrayAccess')] public function testArrayAccess( string $description, string $expression, @@ -6152,9 +6056,7 @@ public static function dataVoid(): array ]; } - /** - * @dataProvider dataVoid - */ + #[DataProvider('dataVoid')] public function testVoid( string $description, string $expression, @@ -6189,9 +6091,7 @@ public static function dataNullableReturnTypes(): array ]; } - /** - * @dataProvider dataNullableReturnTypes - */ + #[DataProvider('dataNullableReturnTypes')] public function testNullableReturnTypes( string $description, string $expression, @@ -6234,9 +6134,7 @@ public static function dataTernary(): array ]; } - /** - * @dataProvider dataTernary - */ + #[DataProvider('dataTernary')] public function testTernary( string $description, string $expression, @@ -6263,9 +6161,7 @@ public static function dataHeredoc(): array ]; } - /** - * @dataProvider dataHeredoc - */ + #[DataProvider('dataHeredoc')] public function testHeredoc( string $description, string $expression, @@ -6434,9 +6330,7 @@ public static function dataTypeElimination(): array ]; } - /** - * @dataProvider dataTypeElimination - */ + #[DataProvider('dataTypeElimination')] public function testTypeElimination( string $description, string $expression, @@ -6469,9 +6363,7 @@ public static function dataMisleadingTypes(): array ]; } - /** - * @dataProvider dataMisleadingTypes - */ + #[DataProvider('dataMisleadingTypes')] public function testMisleadingTypes( string $description, string $expression, @@ -6498,9 +6390,7 @@ public static function dataMisleadingTypesWithoutNamespace(): array ]; } - /** - * @dataProvider dataMisleadingTypesWithoutNamespace - */ + #[DataProvider('dataMisleadingTypesWithoutNamespace')] public function testMisleadingTypesWithoutNamespace( string $description, string $expression, @@ -6531,9 +6421,7 @@ public static function dataUnresolvableTypes(): array ]; } - /** - * @dataProvider dataUnresolvableTypes - */ + #[DataProvider('dataUnresolvableTypes')] public function testUnresolvableTypes( string $description, string $expression, @@ -6560,9 +6448,7 @@ public static function dataCombineTypes(): array ]; } - /** - * @dataProvider dataCombineTypes - */ + #[DataProvider('dataCombineTypes')] public function testCombineTypes( string $description, string $expression, @@ -6599,9 +6485,7 @@ public static function dataConstants(): array ]; } - /** - * @dataProvider dataConstants - */ + #[DataProvider('dataConstants')] public function testConstants( string $description, string $expression, @@ -6628,9 +6512,7 @@ public static function dataFinally(): array ]; } - /** - * @dataProvider dataFinally - */ + #[DataProvider('dataFinally')] public function testFinally( string $description, string $expression, @@ -6643,9 +6525,7 @@ public function testFinally( ); } - /** - * @dataProvider dataFinally - */ + #[DataProvider('dataFinally')] public function testFinallyWithEarlyTermination( string $description, string $expression, @@ -6668,9 +6548,7 @@ public static function dataInheritDocFromInterface(): array ]; } - /** - * @dataProvider dataInheritDocFromInterface - */ + #[DataProvider('dataInheritDocFromInterface')] public function testInheritDocFromInterface( string $description, string $expression, @@ -6683,9 +6561,7 @@ public function testInheritDocFromInterface( ); } - /** - * @dataProvider dataInheritDocFromInterface - */ + #[DataProvider('dataInheritDocFromInterface')] public function testInheritDocWithoutCurlyBracesFromInterface( string $description, string $expression, @@ -6708,9 +6584,7 @@ public static function dataInheritDocFromInterface2(): array ]; } - /** - * @dataProvider dataInheritDocFromInterface2 - */ + #[DataProvider('dataInheritDocFromInterface2')] public function testInheritDocFromInterface2( string $description, string $expression, @@ -6724,9 +6598,7 @@ public function testInheritDocFromInterface2( ); } - /** - * @dataProvider dataInheritDocFromInterface2 - */ + #[DataProvider('dataInheritDocFromInterface2')] public function testInheritDocWithoutCurlyBracesFromInterface2( string $description, string $expression, @@ -6750,9 +6622,7 @@ public static function dataInheritDocFromTrait(): array ]; } - /** - * @dataProvider dataInheritDocFromTrait - */ + #[DataProvider('dataInheritDocFromTrait')] public function testInheritDocFromTrait( string $description, string $expression, @@ -6765,9 +6635,7 @@ public function testInheritDocFromTrait( ); } - /** - * @dataProvider dataInheritDocFromTrait - */ + #[DataProvider('dataInheritDocFromTrait')] public function testInheritDocWithoutCurlyBracesFromTrait( string $description, string $expression, @@ -6790,9 +6658,7 @@ public static function dataInheritDocFromTrait2(): array ]; } - /** - * @dataProvider dataInheritDocFromTrait2 - */ + #[DataProvider('dataInheritDocFromTrait2')] public function testInheritDocFromTrait2( string $description, string $expression, @@ -6807,9 +6673,7 @@ public function testInheritDocFromTrait2( ); } - /** - * @dataProvider dataInheritDocFromTrait2 - */ + #[DataProvider('dataInheritDocFromTrait2')] public function testInheritDocWithoutCurlyBracesFromTrait2( string $description, string $expression, @@ -6850,9 +6714,7 @@ public static function dataResolveStatic(): array ]; } - /** - * @dataProvider dataResolveStatic - */ + #[DataProvider('dataResolveStatic')] public function testResolveStatic( string $description, string $expression, @@ -7079,10 +6941,8 @@ public static function dataForLoopVariables(): array ]; } - /** - * @dataProvider dataLoopVariables - * @dataProvider dataForeachLoopVariables - */ + #[DataProvider('dataLoopVariables')] + #[DataProvider('dataForeachLoopVariables')] public function testForeachLoopVariables( string $description, string $expression, @@ -7097,10 +6957,8 @@ public function testForeachLoopVariables( ); } - /** - * @dataProvider dataLoopVariables - * @dataProvider dataWhileLoopVariables - */ + #[DataProvider('dataLoopVariables')] + #[DataProvider('dataWhileLoopVariables')] public function testWhileLoopVariables( string $description, string $expression, @@ -7115,10 +6973,8 @@ public function testWhileLoopVariables( ); } - /** - * @dataProvider dataLoopVariables - * @dataProvider dataForLoopVariables - */ + #[DataProvider('dataLoopVariables')] + #[DataProvider('dataForLoopVariables')] public function testForLoopVariables( string $description, string $expression, @@ -7225,9 +7081,7 @@ public static function dataDoWhileLoopVariables(): array ]; } - /** - * @dataProvider dataDoWhileLoopVariables - */ + #[DataProvider('dataDoWhileLoopVariables')] public function testDoWhileLoopVariables( string $description, string $expression, @@ -7258,9 +7112,7 @@ public static function dataMultipleClassesInOneFile(): array ]; } - /** - * @dataProvider dataMultipleClassesInOneFile - */ + #[DataProvider('dataMultipleClassesInOneFile')] public function testMultipleClassesInOneFile( string $description, string $expression, @@ -7289,9 +7141,7 @@ public static function dataCallingMultipleClassesInOneFile(): array ]; } - /** - * @dataProvider dataCallingMultipleClassesInOneFile - */ + #[DataProvider('dataCallingMultipleClassesInOneFile')] public function testCallingMultipleClassesInOneFile( string $description, string $expression, @@ -7330,9 +7180,7 @@ public static function dataExplode(): array ]; } - /** - * @dataProvider dataExplode - */ + #[DataProvider('dataExplode')] public function testExplode( string $description, string $expression, @@ -7423,9 +7271,7 @@ public static function dataArrayPointerFunctions(): array ]; } - /** - * @dataProvider dataArrayPointerFunctions - */ + #[DataProvider('dataArrayPointerFunctions')] public function testArrayPointerFunctions( string $description, string $expression, @@ -7500,9 +7346,7 @@ public static function dataReplaceFunctions(): array ]; } - /** - * @dataProvider dataReplaceFunctions - */ + #[DataProvider('dataReplaceFunctions')] public function testReplaceFunctions( string $description, string $expression, @@ -7660,10 +7504,8 @@ public static function dataFilterVarUnchanged(): array ]; } - /** - * @dataProvider dataFilterVar - * @dataProvider dataFilterVarUnchanged - */ + #[DataProvider('dataFilterVar')] + #[DataProvider('dataFilterVarUnchanged')] public function testFilterVar( string $description, string $expression, @@ -7772,9 +7614,7 @@ public static function dataClosureWithUsePassedByReference(): array ]; } - /** - * @dataProvider dataClosureWithUsePassedByReference - */ + #[DataProvider('dataClosureWithUsePassedByReference')] public function testClosureWithUsePassedByReference( string $description, string $expression, @@ -7799,9 +7639,7 @@ public static function dataClosureWithUsePassedByReferenceInMethodCall(): array ]; } - /** - * @dataProvider dataClosureWithUsePassedByReferenceInMethodCall - */ + #[DataProvider('dataClosureWithUsePassedByReferenceInMethodCall')] public function testClosureWithUsePassedByReferenceInMethodCall( string $description, string $expression, @@ -7850,9 +7688,7 @@ public static function dataStaticClosure(): array ]; } - /** - * @dataProvider dataStaticClosure - */ + #[DataProvider('dataStaticClosure')] public function testStaticClosure( string $description, string $expression, @@ -7865,9 +7701,7 @@ public function testStaticClosure( ); } - /** - * @dataProvider dataClosureWithUsePassedByReferenceReturn - */ + #[DataProvider('dataClosureWithUsePassedByReferenceReturn')] public function testClosureWithUsePassedByReferenceReturn( string $description, string $expression, @@ -7896,9 +7730,7 @@ public static function dataClosureWithInferredTypehint(): array ]; } - /** - * @dataProvider dataClosureWithInferredTypehint - */ + #[DataProvider('dataClosureWithInferredTypehint')] public function testClosureWithInferredTypehint( string $description, string $expression, @@ -8004,9 +7836,7 @@ public static function dataTraitsPhpDocs(): array ]; } - /** - * @dataProvider dataTraitsPhpDocs - */ + #[DataProvider('dataTraitsPhpDocs')] public function testTraitsPhpDocs( string $description, string $expression, @@ -8037,9 +7867,7 @@ public static function dataPassedByReference(): array ]; } - /** - * @dataProvider dataPassedByReference - */ + #[DataProvider('dataPassedByReference')] public function testPassedByReference( string $description, string $expression, @@ -8082,9 +7910,7 @@ public static function dataCallables(): array ]; } - /** - * @dataProvider dataCallables - */ + #[DataProvider('dataCallables')] public function testCallables( string $description, string $expression, @@ -8139,9 +7965,7 @@ public static function dataArrayKeysInBranches(): array ]; } - /** - * @dataProvider dataArrayKeysInBranches - */ + #[DataProvider('dataArrayKeysInBranches')] public function testArrayKeysInBranches( string $description, string $expression, @@ -8185,9 +8009,7 @@ public static function dataSpecifiedFunctionCall(): array ]; } - /** - * @dataProvider dataSpecifiedFunctionCall - */ + #[DataProvider('dataSpecifiedFunctionCall')] public function testSpecifiedFunctionCall( string $description, string $expression, @@ -8228,9 +8050,7 @@ public static function dataElementsOnMixed(): array ]; } - /** - * @dataProvider dataElementsOnMixed - */ + #[DataProvider('dataElementsOnMixed')] public function testElementsOnMixed( string $description, string $expression, @@ -8257,9 +8077,7 @@ public static function dataCaseInsensitivePhpDocTypes(): array ]; } - /** - * @dataProvider dataCaseInsensitivePhpDocTypes - */ + #[DataProvider('dataCaseInsensitivePhpDocTypes')] public function testCaseInsensitivePhpDocTypes( string $description, string $expression, @@ -8338,9 +8156,7 @@ public static function dataConstantTypeAfterDuplicateCondition(): array ]; } - /** - * @dataProvider dataConstantTypeAfterDuplicateCondition - */ + #[DataProvider('dataConstantTypeAfterDuplicateCondition')] public function testConstantTypeAfterDuplicateCondition( string $description, string $expression, @@ -8391,9 +8207,7 @@ public static function dataAnonymousClass(): array ]; } - /** - * @dataProvider dataAnonymousClass - */ + #[DataProvider('dataAnonymousClass')] public function testAnonymousClassName( string $description, string $expression, @@ -8418,9 +8232,7 @@ public static function dataAnonymousClassInTrait(): array ]; } - /** - * @dataProvider dataAnonymousClassInTrait - */ + #[DataProvider('dataAnonymousClassInTrait')] public function testAnonymousClassNameInTrait( string $description, string $expression, @@ -8454,9 +8266,7 @@ public static function dataAnonymousClassNameSameLine(): array ]; } - /** - * @dataProvider dataAnonymousClassNameSameLine - */ + #[DataProvider('dataAnonymousClassNameSameLine')] public function testAnonymousClassNameSameLine( string $description, string $expression, @@ -8497,9 +8307,7 @@ public static function dataDynamicConstants(): array ]; } - /** - * @dataProvider dataDynamicConstants - */ + #[DataProvider('dataDynamicConstants')] public function testDynamicConstants( string $description, string $expression, @@ -8539,18 +8347,13 @@ public static function dataDynamicConstantsWithNativeTypes(): array ]; } - /** - * @dataProvider dataDynamicConstantsWithNativeTypes - */ + #[RequiresPhp('>= 8.3')] + #[DataProvider('dataDynamicConstantsWithNativeTypes')] public function testDynamicConstantsWithNativeTypes( string $description, string $expression, ): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->assertTypes( __DIR__ . '/data/dynamic-constant-native-types.php', $description, @@ -8629,9 +8432,7 @@ public static function dataIsset(): array ]; } - /** - * @dataProvider dataIsset - */ + #[DataProvider('dataIsset')] public function testIsset( string $description, string $expression, @@ -8675,9 +8476,7 @@ public static function dataPropertyArrayAssignment(): array ]; } - /** - * @dataProvider dataPropertyArrayAssignment - */ + #[DataProvider('dataPropertyArrayAssignment')] public function testPropertyArrayAssignment( string $description, string $expression, @@ -8766,9 +8565,7 @@ public static function dataGetParentClass(): array ]; } - /** - * @dataProvider dataGetParentClass - */ + #[DataProvider('dataGetParentClass')] public function testGetParentClass( string $description, string $expression, @@ -8799,9 +8596,7 @@ public static function dataIsCountable(): array ]; } - /** - * @dataProvider dataIsCountable - */ + #[DataProvider('dataIsCountable')] public function testIsCountable( string $description, string $expression, @@ -8938,9 +8733,7 @@ public static function dataPhp73Functions(): array ]; } - /** - * @dataProvider dataPhp73Functions - */ + #[DataProvider('dataPhp73Functions')] public function testPhp73Functions( string $description, string $expression, @@ -9067,9 +8860,7 @@ public static function dataPhp74Functions(): array ]; } - /** - * @dataProvider dataPhp74Functions - */ + #[DataProvider('dataPhp74Functions')] public function testPhp74Functions( string $description, string $expression, @@ -9096,9 +8887,7 @@ public static function dataUnionMethods(): array ]; } - /** - * @dataProvider dataUnionMethods - */ + #[DataProvider('dataUnionMethods')] public function testUnionMethods( string $description, string $expression, @@ -9125,9 +8914,7 @@ public static function dataUnionProperties(): array ]; } - /** - * @dataProvider dataUnionProperties - */ + #[DataProvider('dataUnionProperties')] public function testUnionProperties( string $description, string $expression, @@ -9150,9 +8937,7 @@ public static function dataAssignmentInCondition(): array ]; } - /** - * @dataProvider dataAssignmentInCondition - */ + #[DataProvider('dataAssignmentInCondition')] public function testAssignmentInCondition( string $description, string $expression, @@ -9175,9 +8960,7 @@ public static function dataGeneralizeScope(): array ]; } - /** - * @dataProvider dataGeneralizeScope - */ + #[DataProvider('dataGeneralizeScope')] public function testGeneralizeScope( string $description, string $expression, @@ -9200,9 +8983,7 @@ public static function dataGeneralizeScopeRecursiveType(): array ]; } - /** - * @dataProvider dataGeneralizeScopeRecursiveType - */ + #[DataProvider('dataGeneralizeScopeRecursiveType')] public function testGeneralizeScopeRecursiveType( string $description, string $expression, @@ -9233,9 +9014,7 @@ public static function dataArrayShapesInPhpDoc(): array ]; } - /** - * @dataProvider dataArrayShapesInPhpDoc - */ + #[DataProvider('dataArrayShapesInPhpDoc')] public function testArrayShapesInPhpDoc( string $description, string $expression, @@ -9286,9 +9065,7 @@ public static function dataInferPrivatePropertyTypeFromConstructor(): array ]; } - /** - * @dataProvider dataInferPrivatePropertyTypeFromConstructor - */ + #[DataProvider('dataInferPrivatePropertyTypeFromConstructor')] public function testInferPrivatePropertyTypeFromConstructor( string $description, string $expression, @@ -9319,9 +9096,7 @@ public static function dataPropertyNativeTypes(): array ]; } - /** - * @dataProvider dataPropertyNativeTypes - */ + #[DataProvider('dataPropertyNativeTypes')] public function testPropertyNativeTypes( string $description, string $expression, @@ -9352,9 +9127,7 @@ public static function dataArrowFunctions(): array ]; } - /** - * @dataProvider dataArrowFunctions - */ + #[DataProvider('dataArrowFunctions')] public function testArrowFunctions( string $description, string $expression, @@ -9385,9 +9158,7 @@ public static function dataArrowFunctionsInside(): array ]; } - /** - * @dataProvider dataArrowFunctionsInside - */ + #[DataProvider('dataArrowFunctionsInside')] public function testArrowFunctionsInside( string $description, string $expression, @@ -9442,9 +9213,7 @@ public static function dataCoalesceAssign(): array ]; } - /** - * @dataProvider dataCoalesceAssign - */ + #[DataProvider('dataCoalesceAssign')] public function testCoalesceAssign( string $description, string $expression, @@ -9491,9 +9260,7 @@ public static function dataArraySpread(): array ]; } - /** - * @dataProvider dataArraySpread - */ + #[DataProvider('dataArraySpread')] public function testArraySpread( string $description, string $expression, @@ -9516,9 +9283,7 @@ public static function dataPhp74FunctionsIn74(): array ]; } - /** - * @dataProvider dataPhp74FunctionsIn74 - */ + #[DataProvider('dataPhp74FunctionsIn74')] public function testPhp74FunctionsIn74( string $description, string $expression, @@ -9552,9 +9317,7 @@ public static function dataTryCatchScope(): array ]; } - /** - * @dataProvider dataTryCatchScope - */ + #[DataProvider('dataTryCatchScope')] public function testTryCatchScope( string $description, string $expression, @@ -9644,9 +9407,7 @@ public static function dataDeclareStrictTypes(): array ]; } - /** - * @dataProvider dataDeclareStrictTypes - */ + #[DataProvider('dataDeclareStrictTypes')] public function testDeclareStrictTypes(string $file, bool $result): void { self::processFile($file, function (Node $node, Scope $scope) use ($result): void { diff --git a/tests/PHPStan/Analyser/LooseConstComparisonPhp7Test.php b/tests/PHPStan/Analyser/LooseConstComparisonPhp7Test.php index 39bab1d4d7..582997ffa3 100644 --- a/tests/PHPStan/Analyser/LooseConstComparisonPhp7Test.php +++ b/tests/PHPStan/Analyser/LooseConstComparisonPhp7Test.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class LooseConstComparisonPhp7Test extends TypeInferenceTestCase { @@ -18,9 +19,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/LooseConstComparisonPhp8Test.php b/tests/PHPStan/Analyser/LooseConstComparisonPhp8Test.php index 29cd3a9c23..549a1d2de4 100644 --- a/tests/PHPStan/Analyser/LooseConstComparisonPhp8Test.php +++ b/tests/PHPStan/Analyser/LooseConstComparisonPhp8Test.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class LooseConstComparisonPhp8Test extends TypeInferenceTestCase { @@ -18,9 +19,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 17ca49e45d..7d7591117e 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -5,6 +5,7 @@ use EnumTypeAssertions\Foo; use PHPStan\File\FileHelper; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use function array_shift; use function define; @@ -234,9 +235,7 @@ public static function dataFile(): iterable } } - /** - * @dataProvider dataFile - */ + #[DataProvider('dataFile')] public function testFile(string $file): void { $asserts = self::gatherAssertTypes($file); diff --git a/tests/PHPStan/Analyser/ParamClosureThisStubsTest.php b/tests/PHPStan/Analyser/ParamClosureThisStubsTest.php index 2f7e6c47de..cd28ff80f7 100644 --- a/tests/PHPStan/Analyser/ParamClosureThisStubsTest.php +++ b/tests/PHPStan/Analyser/ParamClosureThisStubsTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ParamClosureThisStubsTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataAsserts(): iterable } /** - * @dataProvider dataAsserts * @param mixed ...$args */ + #[DataProvider('dataAsserts')] public function testAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/ParamOutTypeTest.php b/tests/PHPStan/Analyser/ParamOutTypeTest.php index eaceedfeca..251479a95b 100644 --- a/tests/PHPStan/Analyser/ParamOutTypeTest.php +++ b/tests/PHPStan/Analyser/ParamOutTypeTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ParamOutTypeTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/ParameterClosureTypeExtensionArrowFunctionTest.php b/tests/PHPStan/Analyser/ParameterClosureTypeExtensionArrowFunctionTest.php index 5476369a99..778dbf90f7 100644 --- a/tests/PHPStan/Analyser/ParameterClosureTypeExtensionArrowFunctionTest.php +++ b/tests/PHPStan/Analyser/ParameterClosureTypeExtensionArrowFunctionTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ParameterClosureTypeExtensionArrowFunctionTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/ParameterClosureTypeExtensionTest.php b/tests/PHPStan/Analyser/ParameterClosureTypeExtensionTest.php index c44cf2aed7..6079115500 100644 --- a/tests/PHPStan/Analyser/ParameterClosureTypeExtensionTest.php +++ b/tests/PHPStan/Analyser/ParameterClosureTypeExtensionTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ParameterClosureTypeExtensionTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/ParameterOutTypeExtensionTest.php b/tests/PHPStan/Analyser/ParameterOutTypeExtensionTest.php index e7c95c360b..3ad3d0e1f0 100644 --- a/tests/PHPStan/Analyser/ParameterOutTypeExtensionTest.php +++ b/tests/PHPStan/Analyser/ParameterOutTypeExtensionTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ParameterOutTypeExtensionTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataAsserts(): iterable } /** - * @dataProvider dataAsserts * @param mixed ...$args */ + #[DataProvider('dataAsserts')] public function testAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/PathConstantsTest.php b/tests/PHPStan/Analyser/PathConstantsTest.php index 8df12570e9..3a3e124e58 100644 --- a/tests/PHPStan/Analyser/PathConstantsTest.php +++ b/tests/PHPStan/Analyser/PathConstantsTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use const DIRECTORY_SEPARATOR; class PathConstantsTest extends TypeInferenceTestCase @@ -18,9 +19,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/ScopePhpVersionTest.php b/tests/PHPStan/Analyser/ScopePhpVersionTest.php index 4a72193ac2..395cc0891b 100644 --- a/tests/PHPStan/Analyser/ScopePhpVersionTest.php +++ b/tests/PHPStan/Analyser/ScopePhpVersionTest.php @@ -6,6 +6,7 @@ use PhpParser\Node\Expr\Exit_; use PHPStan\Testing\TypeInferenceTestCase; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; class ScopePhpVersionTest extends TypeInferenceTestCase { @@ -24,9 +25,7 @@ public static function dataTestPhpVersion(): array ]; } - /** - * @dataProvider dataTestPhpVersion - */ + #[DataProvider('dataTestPhpVersion')] public function testPhpVersion(string $expected, string $file): void { self::processFile($file, function (Node $node, Scope $scope) use ($expected): void { diff --git a/tests/PHPStan/Analyser/ScopeTest.php b/tests/PHPStan/Analyser/ScopeTest.php index 8452971c0c..e83ed19354 100644 --- a/tests/PHPStan/Analyser/ScopeTest.php +++ b/tests/PHPStan/Analyser/ScopeTest.php @@ -16,10 +16,8 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; -/** - * @covers \PHPStan\Analyser\MutatingScope - */ class ScopeTest extends PHPStanTestCase { @@ -230,9 +228,7 @@ public static function dataGeneralize(): array ]; } - /** - * @dataProvider dataGeneralize - */ + #[DataProvider('dataGeneralize')] public function testGeneralize(Type $a, Type $b, string $expectedTypeDescription): void { /** @var ScopeFactory $scopeFactory */ diff --git a/tests/PHPStan/Analyser/StatementResultTest.php b/tests/PHPStan/Analyser/StatementResultTest.php index 74bec6d6dd..680f528815 100644 --- a/tests/PHPStan/Analyser/StatementResultTest.php +++ b/tests/PHPStan/Analyser/StatementResultTest.php @@ -10,6 +10,7 @@ use PHPStan\Type\IntegerType; use PHPStan\Type\MixedType; use PHPStan\Type\StringType; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class StatementResultTest extends PHPStanTestCase @@ -509,9 +510,7 @@ public static function dataIsAlwaysTerminating(): array ]; } - /** - * @dataProvider dataIsAlwaysTerminating - */ + #[DataProvider('dataIsAlwaysTerminating')] public function testIsAlwaysTerminating( string $code, bool $expectedIsAlwaysTerminating, diff --git a/tests/PHPStan/Analyser/ThrowsTagFromNativeFunctionStubTest.php b/tests/PHPStan/Analyser/ThrowsTagFromNativeFunctionStubTest.php index 1bfcc94ca5..a57c784dd9 100644 --- a/tests/PHPStan/Analyser/ThrowsTagFromNativeFunctionStubTest.php +++ b/tests/PHPStan/Analyser/ThrowsTagFromNativeFunctionStubTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ThrowsTagFromNativeFunctionStubTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/TraitStubFilesTest.php b/tests/PHPStan/Analyser/TraitStubFilesTest.php index 9f052f9fd6..097279e6d3 100644 --- a/tests/PHPStan/Analyser/TraitStubFilesTest.php +++ b/tests/PHPStan/Analyser/TraitStubFilesTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class TraitStubFilesTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/TypeSpecifierContextTest.php b/tests/PHPStan/Analyser/TypeSpecifierContextTest.php index 1be1d94460..10c28510a5 100644 --- a/tests/PHPStan/Analyser/TypeSpecifierContextTest.php +++ b/tests/PHPStan/Analyser/TypeSpecifierContextTest.php @@ -4,6 +4,7 @@ use PHPStan\ShouldNotHappenException; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class TypeSpecifierContextTest extends PHPStanTestCase { @@ -35,9 +36,9 @@ public static function dataContext(): array } /** - * @dataProvider dataContext * @param bool[] $results */ + #[DataProvider('dataContext')] public function testContext(TypeSpecifierContext $context, array $results): void { $this->assertSame($results[0], $context->true()); @@ -70,9 +71,9 @@ public static function dataNegate(): array } /** - * @dataProvider dataNegate * @param bool[] $results */ + #[DataProvider('dataNegate')] public function testNegate(TypeSpecifierContext $context, array $results): void { $this->assertSame($results[0], $context->true()); diff --git a/tests/PHPStan/Analyser/TypeSpecifierTest.php b/tests/PHPStan/Analyser/TypeSpecifierTest.php index 86091b995e..5a06bfb0aa 100644 --- a/tests/PHPStan/Analyser/TypeSpecifierTest.php +++ b/tests/PHPStan/Analyser/TypeSpecifierTest.php @@ -36,6 +36,7 @@ use PHPStan\Type\StringType; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function implode; use function sprintf; use const PHP_INT_MAX; @@ -82,10 +83,10 @@ protected function setUp(): void } /** - * @dataProvider dataCondition * @param mixed[] $expectedPositiveResult * @param mixed[] $expectedNegatedResult */ + #[DataProvider('dataCondition')] public function testCondition(Expr $expr, array $expectedPositiveResult, array $expectedNegatedResult): void { $specifiedTypes = $this->typeSpecifier->specifyTypesInCondition($this->scope, $expr, TypeSpecifierContext::createTruthy()); diff --git a/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceFalseTest.php b/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceFalseTest.php index c1106b1523..8b351b2a57 100644 --- a/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceFalseTest.php +++ b/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceFalseTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class TypeSpecifyingExtensionTypeInferenceFalseTest extends TypeInferenceTestCase { @@ -15,9 +16,9 @@ public static function dataTypeSpecifyingExtensionsFalse(): iterable } /** - * @dataProvider dataTypeSpecifyingExtensionsFalse * @param mixed ...$args */ + #[DataProvider('dataTypeSpecifyingExtensionsFalse')] public function testTypeSpecifyingExtensionsFalse( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceNullTest.php b/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceNullTest.php index b3c8615e4c..de7d4a7e4e 100644 --- a/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceNullTest.php +++ b/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceNullTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class TypeSpecifyingExtensionTypeInferenceNullTest extends TypeInferenceTestCase { @@ -15,9 +16,9 @@ public static function dataTypeSpecifyingExtensionsNull(): iterable } /** - * @dataProvider dataTypeSpecifyingExtensionsNull * @param mixed ...$args */ + #[DataProvider('dataTypeSpecifyingExtensionsNull')] public function testTypeSpecifyingExtensionsNull( string $assertType, string $file, diff --git a/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceTrueTest.php b/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceTrueTest.php index 4c72d55049..25a9e8a0b2 100644 --- a/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceTrueTest.php +++ b/tests/PHPStan/Analyser/TypeSpecifyingExtensionTypeInferenceTrueTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Analyser; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class TypeSpecifyingExtensionTypeInferenceTrueTest extends TypeInferenceTestCase { @@ -15,9 +16,9 @@ public static function dataTypeSpecifyingExtensionsTrue(): iterable } /** - * @dataProvider dataTypeSpecifyingExtensionsTrue * @param mixed ...$args */ + #[DataProvider('dataTypeSpecifyingExtensionsTrue')] public function testTypeSpecifyingExtensionsTrue( string $assertType, string $file, diff --git a/tests/PHPStan/Build/NamedArgumentsRuleTest.php b/tests/PHPStan/Build/NamedArgumentsRuleTest.php index 67573b49e3..f0178e8c1f 100644 --- a/tests/PHPStan/Build/NamedArgumentsRuleTest.php +++ b/tests/PHPStan/Build/NamedArgumentsRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -18,12 +19,9 @@ protected function getRule(): Rule return new NamedArgumentsRule(self::createReflectionProvider(), new PhpVersion(PHP_VERSION_ID)); } + #[RequiresPhp('>= 8.0')] public function testRule(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/named-arguments.php'], [ [ 'You\'re passing a non-default value Exception to parameter $previous but previous argument is passing default value to its parameter ($code). You can skip it and use named argument for $previous instead.', @@ -48,48 +46,36 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testNoFix(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->fix( __DIR__ . '/data/named-arguments-no-errors.php', __DIR__ . '/data/named-arguments-no-errors.php', ); } + #[RequiresPhp('>= 8.0')] public function testFix(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->fix( __DIR__ . '/data/named-arguments.php', __DIR__ . '/data/named-arguments.php.fixed', ); } + #[RequiresPhp('>= 8.0')] public function testFixFileWithMatch(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->fix( __DIR__ . '/data/named-arguments-match.php', __DIR__ . '/data/named-arguments-match.php.fixed', ); } + #[RequiresPhp('>= 8.1')] public function testNewInInitializer(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/named-arguments-new.php'], [ [ 'You\'re passing a non-default value \'bar\' to parameter $d but previous argument is passing default value to its parameter ($c). You can skip it and use named argument for $d instead.', @@ -98,12 +84,9 @@ public function testNewInInitializer(): void ]); } + #[RequiresPhp('>= 8.1')] public function testFixNewInInitializer(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->fix(__DIR__ . '/data/named-arguments-new.php', __DIR__ . '/data/named-arguments-new.php.fixed'); } diff --git a/tests/PHPStan/Command/AnalyseCommandTest.php b/tests/PHPStan/Command/AnalyseCommandTest.php index f47edea747..f2c4f4d73a 100644 --- a/tests/PHPStan/Command/AnalyseCommandTest.php +++ b/tests/PHPStan/Command/AnalyseCommandTest.php @@ -4,6 +4,8 @@ use PHPStan\ShouldNotHappenException; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use Symfony\Component\Console\Tester\CommandTester; use Throwable; use function chdir; @@ -14,15 +16,11 @@ use const DIRECTORY_SEPARATOR; use const PHP_EOL; -/** - * @group exec - */ +#[Group('exec')] class AnalyseCommandTest extends PHPStanTestCase { - /** - * @dataProvider autoDiscoveryPathsProvider - */ + #[DataProvider('autoDiscoveryPathsProvider')] public function testConfigurationAutoDiscovery(string $dir, string $file): void { $originalDir = getcwd(); diff --git a/tests/PHPStan/Command/CommandHelperTest.php b/tests/PHPStan/Command/CommandHelperTest.php index c1d1c5b1fc..4267588e0c 100644 --- a/tests/PHPStan/Command/CommandHelperTest.php +++ b/tests/PHPStan/Command/CommandHelperTest.php @@ -3,6 +3,8 @@ namespace PHPStan\Command; use PHPStan\ShouldNotHappenException; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\NullOutput; @@ -13,9 +15,7 @@ use function stream_get_contents; use const DIRECTORY_SEPARATOR; -/** - * @group exec - */ +#[Group('exec')] class CommandHelperTest extends TestCase { @@ -94,9 +94,9 @@ public static function dataBegin(): array } /** - * @dataProvider dataBegin * @param mixed[] $expectedParameters */ + #[DataProvider('dataBegin')] public function testBegin( string $input, string $expectedOutput, @@ -291,10 +291,10 @@ public static function dataParameters(): array } /** - * @dataProvider dataParameters * @param array $expectedParameters * @throws InceptionNotSuccessfulException */ + #[DataProvider('dataParameters')] public function testResolveParameters( string $configFile, array $expectedParameters, diff --git a/tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterIntegrationTest.php b/tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterIntegrationTest.php index 07c6d9ffe2..4cab9de19b 100644 --- a/tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterIntegrationTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterIntegrationTest.php @@ -4,6 +4,7 @@ use Nette\Utils\Json; use PHPStan\ShouldNotHappenException; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use function array_sum; use function chdir; @@ -15,9 +16,7 @@ use function unlink; use const PHP_BINARY; -/** - * @group exec - */ +#[Group('exec')] class BaselineNeonErrorFormatterIntegrationTest extends TestCase { diff --git a/tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterTest.php index 8b3a49e012..4712721634 100644 --- a/tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterTest.php @@ -13,6 +13,7 @@ use PHPStan\ShouldNotHappenException; use PHPStan\Testing\ErrorFormatterTestCase; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\StreamOutput; use function fopen; @@ -112,10 +113,9 @@ public static function dataFormatterOutputProvider(): iterable } /** - * @dataProvider dataFormatterOutputProvider - * * @param mixed[] $expected */ + #[DataProvider('dataFormatterOutputProvider')] public function testFormatErrors( string $message, int $exitCode, @@ -240,9 +240,9 @@ public static function outputOrderingProvider(): Generator } /** - * @dataProvider outputOrderingProvider * @param list $errors */ + #[DataProvider('outputOrderingProvider')] public function testOutputOrdering(array $errors): void { $formatter = new BaselineNeonErrorFormatter(new SimpleRelativePathHelper(self::DIRECTORY_PATH)); @@ -395,10 +395,9 @@ public static function endOfFileNewlinesProvider(): Generator } /** - * @dataProvider endOfFileNewlinesProvider - * * @param list $errors */ + #[DataProvider('endOfFileNewlinesProvider')] public function testEndOfFileNewlines( array $errors, string $existingBaselineContent, @@ -553,10 +552,10 @@ public static function dataFormatErrorsWithIdentifiers(): iterable } /** - * @dataProvider dataFormatErrorsWithIdentifiers * @param list $errors * @param mixed[] $expectedOutput */ + #[DataProvider('dataFormatErrorsWithIdentifiers')] public function testFormatErrorsWithIdentifiers(array $errors, array $expectedOutput): void { $formatter = new BaselineNeonErrorFormatter(new SimpleRelativePathHelper(__DIR__)); diff --git a/tests/PHPStan/Command/ErrorFormatter/BaselinePhpErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/BaselinePhpErrorFormatterTest.php index 78244e2a67..868154dd43 100644 --- a/tests/PHPStan/Command/ErrorFormatter/BaselinePhpErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/BaselinePhpErrorFormatterTest.php @@ -6,6 +6,7 @@ use PHPStan\Command\AnalysisResult; use PHPStan\File\ParentDirectoryRelativePathHelper; use PHPStan\Testing\ErrorFormatterTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class BaselinePhpErrorFormatterTest extends ErrorFormatterTestCase { @@ -151,9 +152,9 @@ public static function dataFormatErrors(): iterable } /** - * @dataProvider dataFormatErrors * @param list $errors */ + #[DataProvider('dataFormatErrors')] public function testFormatErrors(array $errors, string $expectedOutput): void { $formatter = new BaselinePhpErrorFormatter(new ParentDirectoryRelativePathHelper(__DIR__)); diff --git a/tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php index da53c07c52..48e906017c 100644 --- a/tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php @@ -6,6 +6,7 @@ use PHPStan\Command\AnalysisResult; use PHPStan\File\SimpleRelativePathHelper; use PHPStan\Testing\ErrorFormatterTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class CheckstyleErrorFormatterTest extends ErrorFormatterTestCase @@ -110,10 +111,7 @@ public static function dataFormatterOutputProvider(): iterable ]; } - /** - * @dataProvider dataFormatterOutputProvider - * - */ + #[DataProvider('dataFormatterOutputProvider')] public function testFormatErrors( string $message, int $exitCode, diff --git a/tests/PHPStan/Command/ErrorFormatter/GithubErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/GithubErrorFormatterTest.php index 0d185dd949..45e79a16f1 100644 --- a/tests/PHPStan/Command/ErrorFormatter/GithubErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/GithubErrorFormatterTest.php @@ -5,6 +5,7 @@ use PHPStan\File\FuzzyRelativePathHelper; use PHPStan\File\NullRelativePathHelper; use PHPStan\Testing\ErrorFormatterTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class GithubErrorFormatterTest extends ErrorFormatterTestCase @@ -75,10 +76,7 @@ public static function dataFormatterOutputProvider(): iterable ]; } - /** - * @dataProvider dataFormatterOutputProvider - * - */ + #[DataProvider('dataFormatterOutputProvider')] public function testFormatErrors( string $message, int $exitCode, diff --git a/tests/PHPStan/Command/ErrorFormatter/GitlabFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/GitlabFormatterTest.php index 27c95d82c6..8569f09fad 100644 --- a/tests/PHPStan/Command/ErrorFormatter/GitlabFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/GitlabFormatterTest.php @@ -4,6 +4,7 @@ use PHPStan\File\SimpleRelativePathHelper; use PHPStan\Testing\ErrorFormatterTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class GitlabFormatterTest extends ErrorFormatterTestCase @@ -283,11 +284,7 @@ public static function dataFormatterOutputProvider(): iterable ]; } - /** - * @dataProvider dataFormatterOutputProvider - * - * - */ + #[DataProvider('dataFormatterOutputProvider')] public function testFormatErrors( string $message, int $exitCode, diff --git a/tests/PHPStan/Command/ErrorFormatter/JsonErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/JsonErrorFormatterTest.php index 61be3c1b4d..19d05899f2 100644 --- a/tests/PHPStan/Command/ErrorFormatter/JsonErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/JsonErrorFormatterTest.php @@ -6,6 +6,7 @@ use PHPStan\Analyser\Error; use PHPStan\Command\AnalysisResult; use PHPStan\Testing\ErrorFormatterTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class JsonErrorFormatterTest extends ErrorFormatterTestCase @@ -193,10 +194,7 @@ public static function dataFormatterOutputProvider(): iterable ]; } - /** - * @dataProvider dataFormatterOutputProvider - * - */ + #[DataProvider('dataFormatterOutputProvider')] public function testPrettyFormatErrors( string $message, int $exitCode, @@ -215,11 +213,7 @@ public function testPrettyFormatErrors( $this->assertJsonStringEqualsJsonString($expected, $this->getOutputContent()); } - /** - * @dataProvider dataFormatterOutputProvider - * - * - */ + #[DataProvider('dataFormatterOutputProvider')] public function testFormatErrors( string $message, int $exitCode, @@ -245,9 +239,7 @@ public static function dataFormatTip(): iterable yield ['this check by setting treatPhpDocTypesAsCertain: false in your %configurationFile%.', 'this check by setting treatPhpDocTypesAsCertain: false in your %configurationFile%.']; } - /** - * @dataProvider dataFormatTip - */ + #[DataProvider('dataFormatTip')] public function testFormatTip(string $tip, string $expectedTip): void { $formatter = new JsonErrorFormatter(false); diff --git a/tests/PHPStan/Command/ErrorFormatter/JunitErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/JunitErrorFormatterTest.php index 8c7c1af412..6c070585ac 100644 --- a/tests/PHPStan/Command/ErrorFormatter/JunitErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/JunitErrorFormatterTest.php @@ -7,6 +7,7 @@ use Override; use PHPStan\File\SimpleRelativePathHelper; use PHPStan\Testing\ErrorFormatterTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class JunitErrorFormatterTest extends ErrorFormatterTestCase { @@ -132,9 +133,8 @@ public static function dataFormatterOutputProvider(): Generator /** * Test generated use cases for JUnit output format. - * - * @dataProvider dataFormatterOutputProvider */ + #[DataProvider('dataFormatterOutputProvider')] public function testFormatErrors( int $exitCode, int $numFileErrors, diff --git a/tests/PHPStan/Command/ErrorFormatter/RawErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/RawErrorFormatterTest.php index 117645e0b7..f393ed5c9e 100644 --- a/tests/PHPStan/Command/ErrorFormatter/RawErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/RawErrorFormatterTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Command\ErrorFormatter; use PHPStan\Testing\ErrorFormatterTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class RawErrorFormatterTest extends ErrorFormatterTestCase @@ -102,9 +103,9 @@ public static function dataFormatterOutputProvider(): iterable } /** - * @dataProvider dataFormatterOutputProvider * @param array{int, int}|int $numFileErrors */ + #[DataProvider('dataFormatterOutputProvider')] public function testFormatErrors( string $message, int $exitCode, diff --git a/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php index 04291adae9..1a08cb4a9b 100644 --- a/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php @@ -9,6 +9,7 @@ use PHPStan\File\NullRelativePathHelper; use PHPStan\File\SimpleRelativePathHelper; use PHPStan\Testing\ErrorFormatterTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function getenv; use function putenv; use function sprintf; @@ -230,10 +231,10 @@ public static function dataFormatterOutputProvider(): iterable } /** - * @dataProvider dataFormatterOutputProvider * @param array{int, int}|int $numFileErrors * @param array $extraEnvVars */ + #[DataProvider('dataFormatterOutputProvider')] public function testFormatErrors( string $message, int $exitCode, diff --git a/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php index e74d1354d4..5c94ece3e9 100644 --- a/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php @@ -5,6 +5,7 @@ use PHPStan\File\FuzzyRelativePathHelper; use PHPStan\File\NullRelativePathHelper; use PHPStan\Testing\ErrorFormatterTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class TeamcityErrorFormatterTest extends ErrorFormatterTestCase @@ -93,9 +94,9 @@ public static function dataFormatterOutputProvider(): iterable } /** - * @dataProvider dataFormatterOutputProvider * @param array{int, int}|int $numFileErrors */ + #[DataProvider('dataFormatterOutputProvider')] public function testFormatErrors( string $message, int $exitCode, diff --git a/tests/PHPStan/Command/IgnoredRegexValidatorTest.php b/tests/PHPStan/Command/IgnoredRegexValidatorTest.php index 2e072fbd23..2b64d9e534 100644 --- a/tests/PHPStan/Command/IgnoredRegexValidatorTest.php +++ b/tests/PHPStan/Command/IgnoredRegexValidatorTest.php @@ -6,6 +6,7 @@ use Hoa\File\Read; use PHPStan\PhpDoc\TypeStringResolver; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class IgnoredRegexValidatorTest extends PHPStanTestCase { @@ -152,9 +153,9 @@ public static function dataValidate(): array } /** - * @dataProvider dataValidate * @param string[] $expectedTypes */ + #[DataProvider('dataValidate')] public function testValidate( string $regex, array $expectedTypes, diff --git a/tests/PHPStan/File/FileExcluderTest.php b/tests/PHPStan/File/FileExcluderTest.php index a81740afba..02aff99453 100644 --- a/tests/PHPStan/File/FileExcluderTest.php +++ b/tests/PHPStan/File/FileExcluderTest.php @@ -3,14 +3,15 @@ namespace PHPStan\File; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class FileExcluderTest extends PHPStanTestCase { /** - * @dataProvider dataExcludeOnWindows * @param string[] $analyseExcludes */ + #[DataProvider('dataExcludeOnWindows')] public function testFilesAreExcludedFromAnalysingOnWindows( string $filePath, array $analyseExcludes, @@ -116,9 +117,9 @@ public static function dataExcludeOnWindows(): array } /** - * @dataProvider dataExcludeOnUnix * @param string[] $analyseExcludes */ + #[DataProvider('dataExcludeOnUnix')] public function testFilesAreExcludedFromAnalysingOnUnix( string $filePath, array $analyseExcludes, @@ -239,9 +240,9 @@ public static function dataNoImplicitWildcard(): iterable } /** - * @dataProvider dataNoImplicitWildcard * @param string[] $analyseExcludes */ + #[DataProvider('dataNoImplicitWildcard')] public function testNoImplicitWildcard( string $filePath, array $analyseExcludes, diff --git a/tests/PHPStan/File/FileHelperTest.php b/tests/PHPStan/File/FileHelperTest.php index 285f6f3a0e..ac2cef5fd1 100644 --- a/tests/PHPStan/File/FileHelperTest.php +++ b/tests/PHPStan/File/FileHelperTest.php @@ -3,6 +3,7 @@ namespace PHPStan\File; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class FileHelperTest extends PHPStanTestCase { @@ -25,9 +26,7 @@ public static function dataAbsolutizePathOnWindows(): array ]; } - /** - * @dataProvider dataAbsolutizePathOnWindows - */ + #[DataProvider('dataAbsolutizePathOnWindows')] public function testAbsolutizePathOnWindows(string $path, string $absolutePath): void { $this->skipIfNotOnWindows(); @@ -54,9 +53,7 @@ public static function dataAbsolutizePathOnLinuxOrMac(): array ]; } - /** - * @dataProvider dataAbsolutizePathOnLinuxOrMac - */ + #[DataProvider('dataAbsolutizePathOnLinuxOrMac')] public function testAbsolutizePathOnLinuxOrMac(string $path, string $absolutePath): void { $this->skipIfNotOnUnix(); @@ -81,9 +78,7 @@ public static function dataNormalizePathOnWindows(): array ]; } - /** - * @dataProvider dataNormalizePathOnWindows - */ + #[DataProvider('dataNormalizePathOnWindows')] public function testNormalizePathOnWindows(string $path, string $normalizedPath): void { $this->skipIfNotOnWindows(); @@ -109,9 +104,7 @@ public static function dataNormalizePathOnLinuxOrMac(): array ]; } - /** - * @dataProvider dataNormalizePathOnLinuxOrMac - */ + #[DataProvider('dataNormalizePathOnLinuxOrMac')] public function testNormalizePathOnLinuxOrMac(string $path, string $normalizedPath): void { $this->skipIfNotOnUnix(); diff --git a/tests/PHPStan/File/ParentDirectoryRelativePathHelperTest.php b/tests/PHPStan/File/ParentDirectoryRelativePathHelperTest.php index 3a409211b4..4194588890 100644 --- a/tests/PHPStan/File/ParentDirectoryRelativePathHelperTest.php +++ b/tests/PHPStan/File/ParentDirectoryRelativePathHelperTest.php @@ -2,6 +2,7 @@ namespace PHPStan\File; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class ParentDirectoryRelativePathHelperTest extends TestCase @@ -103,9 +104,7 @@ public static function dataGetRelativePath(): array ]; } - /** - * @dataProvider dataGetRelativePath - */ + #[DataProvider('dataGetRelativePath')] public function testGetRelativePath( string $parentDirectory, string $filename, diff --git a/tests/PHPStan/File/RelativePathHelperTest.php b/tests/PHPStan/File/RelativePathHelperTest.php index 43e2ed52fa..7c484879cc 100644 --- a/tests/PHPStan/File/RelativePathHelperTest.php +++ b/tests/PHPStan/File/RelativePathHelperTest.php @@ -2,6 +2,7 @@ namespace PHPStan\File; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function array_map; use function str_replace; @@ -180,9 +181,9 @@ public static function dataGetRelativePath(): array } /** - * @dataProvider dataGetRelativePath * @param string[] $analysedPaths */ + #[DataProvider('dataGetRelativePath')] public function testGetRelativePathOnUnix( string $currentWorkingDirectory, array $analysedPaths, @@ -198,9 +199,9 @@ public function testGetRelativePathOnUnix( } /** - * @dataProvider dataGetRelativePath * @param string[] $analysedPaths */ + #[DataProvider('dataGetRelativePath')] public function testGetRelativePathOnWindows( string $currentWorkingDirectory, array $analysedPaths, @@ -247,9 +248,9 @@ public static function dataGetRelativePathWindowsSpecific(): array } /** - * @dataProvider dataGetRelativePathWindowsSpecific * @param string[] $analysedPaths */ + #[DataProvider('dataGetRelativePathWindowsSpecific')] public function testGetRelativePathWindowsSpecific( string $currentWorkingDirectory, array $analysedPaths, diff --git a/tests/PHPStan/Generics/GenericsIntegrationTest.php b/tests/PHPStan/Generics/GenericsIntegrationTest.php index a100809355..e8309a0846 100644 --- a/tests/PHPStan/Generics/GenericsIntegrationTest.php +++ b/tests/PHPStan/Generics/GenericsIntegrationTest.php @@ -3,10 +3,9 @@ namespace PHPStan\Generics; use PHPStan\Testing\LevelsTestCase; +use PHPUnit\Framework\Attributes\Group; -/** - * @group levels - */ +#[Group('levels')] class GenericsIntegrationTest extends LevelsTestCase { diff --git a/tests/PHPStan/Generics/TemplateTypeFactoryTest.php b/tests/PHPStan/Generics/TemplateTypeFactoryTest.php index a5f966e305..5fe62d6b3c 100644 --- a/tests/PHPStan/Generics/TemplateTypeFactoryTest.php +++ b/tests/PHPStan/Generics/TemplateTypeFactoryTest.php @@ -15,6 +15,7 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class TemplateTypeFactoryTest extends PHPStanTestCase @@ -74,9 +75,7 @@ public static function dataCreate(): array ]; } - /** - * @dataProvider dataCreate - */ + #[DataProvider('dataCreate')] public function testCreate(?Type $bound, Type $expectedBound): void { $scope = TemplateTypeScope::createWithFunction('a'); diff --git a/tests/PHPStan/Levels/InferPrivatePropertyTypeFromConstructorIntegrationTest.php b/tests/PHPStan/Levels/InferPrivatePropertyTypeFromConstructorIntegrationTest.php index d8d3c28878..3338348583 100644 --- a/tests/PHPStan/Levels/InferPrivatePropertyTypeFromConstructorIntegrationTest.php +++ b/tests/PHPStan/Levels/InferPrivatePropertyTypeFromConstructorIntegrationTest.php @@ -3,10 +3,9 @@ namespace PHPStan\Levels; use PHPStan\Testing\LevelsTestCase; +use PHPUnit\Framework\Attributes\Group; -/** - * @group levels - */ +#[Group('levels')] class InferPrivatePropertyTypeFromConstructorIntegrationTest extends LevelsTestCase { diff --git a/tests/PHPStan/Levels/LevelsIntegrationTest.php b/tests/PHPStan/Levels/LevelsIntegrationTest.php index 7ac3a0276f..12499dce44 100644 --- a/tests/PHPStan/Levels/LevelsIntegrationTest.php +++ b/tests/PHPStan/Levels/LevelsIntegrationTest.php @@ -3,11 +3,10 @@ namespace PHPStan\Levels; use PHPStan\Testing\LevelsTestCase; +use PHPUnit\Framework\Attributes\Group; use const PHP_VERSION_ID; -/** - * @group levels - */ +#[Group('levels')] class LevelsIntegrationTest extends LevelsTestCase { diff --git a/tests/PHPStan/Levels/NamedArgumentsIntegrationTest.php b/tests/PHPStan/Levels/NamedArgumentsIntegrationTest.php index d35d7dade7..999427f6c6 100644 --- a/tests/PHPStan/Levels/NamedArgumentsIntegrationTest.php +++ b/tests/PHPStan/Levels/NamedArgumentsIntegrationTest.php @@ -3,10 +3,9 @@ namespace PHPStan\Levels; use PHPStan\Testing\LevelsTestCase; +use PHPUnit\Framework\Attributes\Group; -/** - * @group levels - */ +#[Group('levels')] class NamedArgumentsIntegrationTest extends LevelsTestCase { diff --git a/tests/PHPStan/Levels/StubValidatorIntegrationTest.php b/tests/PHPStan/Levels/StubValidatorIntegrationTest.php index 59ded11998..d76d9045c0 100644 --- a/tests/PHPStan/Levels/StubValidatorIntegrationTest.php +++ b/tests/PHPStan/Levels/StubValidatorIntegrationTest.php @@ -3,10 +3,9 @@ namespace PHPStan\Levels; use PHPStan\Testing\LevelsTestCase; +use PHPUnit\Framework\Attributes\Group; -/** - * @group levels - */ +#[Group('levels')] class StubValidatorIntegrationTest extends LevelsTestCase { diff --git a/tests/PHPStan/Levels/StubsIntegrationTest.php b/tests/PHPStan/Levels/StubsIntegrationTest.php index 089c9b5495..c8be90cd53 100644 --- a/tests/PHPStan/Levels/StubsIntegrationTest.php +++ b/tests/PHPStan/Levels/StubsIntegrationTest.php @@ -3,10 +3,9 @@ namespace PHPStan\Levels; use PHPStan\Testing\LevelsTestCase; +use PHPUnit\Framework\Attributes\Group; -/** - * @group levels - */ +#[Group('levels')] class StubsIntegrationTest extends LevelsTestCase { diff --git a/tests/PHPStan/Node/AttributeArgRuleTest.php b/tests/PHPStan/Node/AttributeArgRuleTest.php index 37c6f98df1..796d5d3bdb 100644 --- a/tests/PHPStan/Node/AttributeArgRuleTest.php +++ b/tests/PHPStan/Node/AttributeArgRuleTest.php @@ -5,7 +5,8 @@ use PhpParser\Node; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -32,8 +33,8 @@ public static function dataRule(): iterable /** * @param int[] $lines - * @dataProvider dataRule */ + #[DataProvider('dataRule')] public function testRule(string $file, string $expectedError, array $lines): void { $errors = []; @@ -43,12 +44,9 @@ public function testRule(string $file, string $expectedError, array $lines): voi $this->analyse([$file], $errors); } + #[RequiresPhp('>= 8.1')] public function testEnumCaseAttribute(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/enum-case-attribute.php'], [ [ AttributeArgRule::ERROR_MESSAGE, diff --git a/tests/PHPStan/Node/AttributeGroupRuleTest.php b/tests/PHPStan/Node/AttributeGroupRuleTest.php index 07d6ed9e2d..67141a33b2 100644 --- a/tests/PHPStan/Node/AttributeGroupRuleTest.php +++ b/tests/PHPStan/Node/AttributeGroupRuleTest.php @@ -5,6 +5,7 @@ use PhpParser\Node; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @extends RuleTestCase @@ -31,8 +32,8 @@ public static function dataRule(): iterable /** * @param int[] $lines - * @dataProvider dataRule */ + #[DataProvider('dataRule')] public function testRule(string $file, string $expectedError, array $lines): void { $errors = []; diff --git a/tests/PHPStan/Node/AttributeRuleTest.php b/tests/PHPStan/Node/AttributeRuleTest.php index 52b4c55d65..135a0ca20d 100644 --- a/tests/PHPStan/Node/AttributeRuleTest.php +++ b/tests/PHPStan/Node/AttributeRuleTest.php @@ -5,6 +5,7 @@ use PhpParser\Node; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @extends RuleTestCase @@ -31,8 +32,8 @@ public static function dataRule(): iterable /** * @param int[] $lines - * @dataProvider dataRule */ + #[DataProvider('dataRule')] public function testRule(string $file, string $expectedError, array $lines): void { $errors = []; diff --git a/tests/PHPStan/Node/FileNodeTest.php b/tests/PHPStan/Node/FileNodeTest.php index 47856f6e04..aebcd787be 100644 --- a/tests/PHPStan/Node/FileNodeTest.php +++ b/tests/PHPStan/Node/FileNodeTest.php @@ -9,6 +9,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function get_class; use function sprintf; use const DIRECTORY_SEPARATOR; @@ -72,9 +73,7 @@ public static function dataRule(): iterable ]; } - /** - * @dataProvider dataRule - */ + #[DataProvider('dataRule')] public function testRule(string $file, string $expectedError, int $line): void { $this->analyse([$file], [ diff --git a/tests/PHPStan/Parallel/ParallelAnalyserIntegrationTest.php b/tests/PHPStan/Parallel/ParallelAnalyserIntegrationTest.php index 77e1a2000d..fb60543a17 100644 --- a/tests/PHPStan/Parallel/ParallelAnalyserIntegrationTest.php +++ b/tests/PHPStan/Parallel/ParallelAnalyserIntegrationTest.php @@ -6,6 +6,8 @@ use Nette\Utils\Json; use PHPStan\File\FileHelper; use PHPStan\ShouldNotHappenException; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use function array_map; use function escapeshellarg; @@ -18,9 +20,7 @@ use function uniqid; use const PHP_BINARY; -/** - * @group exec - */ +#[Group('exec')] class ParallelAnalyserIntegrationTest extends TestCase { @@ -32,9 +32,7 @@ public static function dataRun(): array ]; } - /** - * @dataProvider dataRun - */ + #[DataProvider('dataRun')] public function testRun(string $command): void { $tmpDir = sys_get_temp_dir() . '/' . md5(uniqid()); diff --git a/tests/PHPStan/Parallel/SchedulerTest.php b/tests/PHPStan/Parallel/SchedulerTest.php index 375ec004f7..284af8d55c 100644 --- a/tests/PHPStan/Parallel/SchedulerTest.php +++ b/tests/PHPStan/Parallel/SchedulerTest.php @@ -2,6 +2,7 @@ namespace PHPStan\Parallel; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function array_fill; use function array_map; @@ -71,13 +72,13 @@ public static function dataSchedule(): array } /** - * @dataProvider dataSchedule * @param positive-int $jobSize * @param positive-int $maximumNumberOfProcesses * @param positive-int $minimumNumberOfJobsPerProcess * @param 0|positive-int $numberOfFiles * @param array $expectedJobSizes */ + #[DataProvider('dataSchedule')] public function testSchedule( int $cpuCores, int $maximumNumberOfProcesses, diff --git a/tests/PHPStan/Parser/CachedParserTest.php b/tests/PHPStan/Parser/CachedParserTest.php index ad7c18a52e..9ea74505cf 100644 --- a/tests/PHPStan/Parser/CachedParserTest.php +++ b/tests/PHPStan/Parser/CachedParserTest.php @@ -8,14 +8,13 @@ use PHPStan\File\FileHelper; use PHPStan\File\FileReader; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; class CachedParserTest extends PHPStanTestCase { - /** - * @dataProvider dataParseFileClearCache - */ + #[DataProvider('dataParseFileClearCache')] public function testParseFileClearCache( int $cachedNodesByStringCountMax, int $cachedNodesByStringCountExpected, diff --git a/tests/PHPStan/Parser/CleaningParserTest.php b/tests/PHPStan/Parser/CleaningParserTest.php index fc54ad5e28..c94558ed89 100644 --- a/tests/PHPStan/Parser/CleaningParserTest.php +++ b/tests/PHPStan/Parser/CleaningParserTest.php @@ -9,6 +9,7 @@ use PHPStan\Node\Printer\Printer; use PHPStan\Php\PhpVersion; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use const PHP_VERSION_ID; class CleaningParserTest extends PHPStanTestCase @@ -60,9 +61,7 @@ public static function dataParse(): iterable ]; } - /** - * @dataProvider dataParse - */ + #[DataProvider('dataParse')] public function testParse( string $beforeFile, string $afterFile, diff --git a/tests/PHPStan/Parser/ParserTest.php b/tests/PHPStan/Parser/ParserTest.php index 633beff241..7dd2e22a05 100644 --- a/tests/PHPStan/Parser/ParserTest.php +++ b/tests/PHPStan/Parser/ParserTest.php @@ -3,12 +3,9 @@ namespace PHPStan\Parser; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function count; -/** - * @covers \PHPStan\Parser\RichParser - * @covers \PHPStan\Parser\SimpleParser - */ class ParserTest extends PHPStanTestCase { @@ -59,10 +56,10 @@ public static function dataVariadicCallLikes(): iterable } /** - * @dataProvider dataVariadicCallLikes * @param array|array> $expectedVariadics * @throws ParserErrorsException */ + #[DataProvider('dataVariadicCallLikes')] public function testSimpleParserVariadicCallLikes(string $file, string $attributeName, array $expectedVariadics): void { /** @var SimpleParser $parser */ @@ -78,10 +75,10 @@ public function testSimpleParserVariadicCallLikes(string $file, string $attribut } /** - * @dataProvider dataVariadicCallLikes * @param array|array> $expectedVariadics * @throws ParserErrorsException */ + #[DataProvider('dataVariadicCallLikes')] public function testRichParserVariadicCallLikes(string $file, string $attributeName, array $expectedVariadics): void { /** @var RichParser $parser */ diff --git a/tests/PHPStan/Parser/RichParserTest.php b/tests/PHPStan/Parser/RichParserTest.php index eb067b0f54..a821dbdb5c 100644 --- a/tests/PHPStan/Parser/RichParserTest.php +++ b/tests/PHPStan/Parser/RichParserTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Parser; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use const PHP_EOL; class RichParserTest extends PHPStanTestCase @@ -313,9 +314,9 @@ public static function dataLinesToIgnore(): iterable } /** - * @dataProvider dataLinesToIgnore * @param array|null> $expectedLines */ + #[DataProvider('dataLinesToIgnore')] public function testLinesToIgnore(string $code, array $expectedLines): void { /** @var RichParser $parser */ @@ -526,9 +527,9 @@ public static function dataLinesToIgnoreParseErrors(): iterable } /** - * @dataProvider dataLinesToIgnoreParseErrors * @param array> $expectedErrors */ + #[DataProvider('dataLinesToIgnoreParseErrors')] public function testLinesToIgnoreParseErrors(string $code, array $expectedErrors): void { /** @var RichParser $parser */ diff --git a/tests/PHPStan/Php/PhpVersionFactoryTest.php b/tests/PHPStan/Php/PhpVersionFactoryTest.php index 7a070bdb49..adc5564253 100644 --- a/tests/PHPStan/Php/PhpVersionFactoryTest.php +++ b/tests/PHPStan/Php/PhpVersionFactoryTest.php @@ -2,6 +2,7 @@ namespace PHPStan\Php; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use const PHP_VERSION_ID; @@ -92,9 +93,7 @@ public static function dataCreate(): array ]; } - /** - * @dataProvider dataCreate - */ + #[DataProvider('dataCreate')] public function testCreate( ?int $versionId, ?string $composerPhpVersion, diff --git a/tests/PHPStan/Php/PhpVersionsTest.php b/tests/PHPStan/Php/PhpVersionsTest.php index 8549c9abbc..692592d138 100644 --- a/tests/PHPStan/Php/PhpVersionsTest.php +++ b/tests/PHPStan/Php/PhpVersionsTest.php @@ -7,14 +7,13 @@ use PHPStan\Type\IntegerRangeType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class PhpVersionsTest extends TestCase { - /** - * @dataProvider dataProducesWarningForFinalPrivateMethods - */ + #[DataProvider('dataProducesWarningForFinalPrivateMethods')] public function testProducesWarningForFinalPrivateMethods(TrinaryLogic $expected, Type $versionType): void { $phpVersions = new PhpVersions($versionType); diff --git a/tests/PHPStan/PhpDoc/TypeDescriptionTest.php b/tests/PHPStan/PhpDoc/TypeDescriptionTest.php index 63028a0202..e7147bb077 100644 --- a/tests/PHPStan/PhpDoc/TypeDescriptionTest.php +++ b/tests/PHPStan/PhpDoc/TypeDescriptionTest.php @@ -19,6 +19,7 @@ use PHPStan\Type\StringType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class TypeDescriptionTest extends PHPStanTestCase @@ -69,9 +70,7 @@ public static function dataTest(): iterable yield ['array{\'"foo"\': int}', $builder->getArray()]; } - /** - * @dataProvider dataTest - */ + #[DataProvider('dataTest')] public function testParsingDesiredTypeDescription(string $description, Type $expectedType): void { $typeStringResolver = self::getContainer()->getByType(TypeStringResolver::class); @@ -83,9 +82,7 @@ public function testParsingDesiredTypeDescription(string $description, Type $exp $this->assertTrue($type->equals($newType), sprintf('Parsing %s again did not result in %s, but in %s', $newDescription, $type->describe(VerbosityLevel::value()), $newType->describe(VerbosityLevel::value()))); } - /** - * @dataProvider dataTest - */ + #[DataProvider('dataTest')] public function testDesiredTypeDescription(string $description, Type $expectedType): void { $this->assertSame($description, $expectedType->describe(VerbosityLevel::value())); diff --git a/tests/PHPStan/Reflection/AllowedSubTypesClassReflectionExtensionTest.php b/tests/PHPStan/Reflection/AllowedSubTypesClassReflectionExtensionTest.php index 0f591da556..5ca035e52c 100644 --- a/tests/PHPStan/Reflection/AllowedSubTypesClassReflectionExtensionTest.php +++ b/tests/PHPStan/Reflection/AllowedSubTypesClassReflectionExtensionTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Reflection; use PHPStan\Testing\TypeInferenceTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class AllowedSubTypesClassReflectionExtensionTest extends TypeInferenceTestCase { @@ -13,9 +14,9 @@ public static function dataFileAsserts(): iterable } /** - * @dataProvider dataFileAsserts * @param mixed ...$args */ + #[DataProvider('dataFileAsserts')] public function testFileAsserts( string $assertType, string $file, diff --git a/tests/PHPStan/Reflection/Annotations/AnnotationsMethodsClassReflectionExtensionTest.php b/tests/PHPStan/Reflection/Annotations/AnnotationsMethodsClassReflectionExtensionTest.php index 325bd25e36..2be55e8284 100644 --- a/tests/PHPStan/Reflection/Annotations/AnnotationsMethodsClassReflectionExtensionTest.php +++ b/tests/PHPStan/Reflection/Annotations/AnnotationsMethodsClassReflectionExtensionTest.php @@ -12,6 +12,7 @@ use PHPStan\Reflection\Php\PhpMethodReflection; use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function array_merge; use function count; use function sprintf; @@ -958,9 +959,9 @@ public static function dataMethods(): array } /** - * @dataProvider dataMethods * @param array $methods */ + #[DataProvider('dataMethods')] public function testMethods(string $className, array $methods): void { $reflectionProvider = self::createReflectionProvider(); diff --git a/tests/PHPStan/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtensionTest.php b/tests/PHPStan/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtensionTest.php index fd98a90115..9e75d926b3 100644 --- a/tests/PHPStan/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtensionTest.php +++ b/tests/PHPStan/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtensionTest.php @@ -11,6 +11,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class AnnotationsPropertiesClassReflectionExtensionTest extends PHPStanTestCase @@ -272,9 +273,9 @@ public static function dataProperties(): array } /** - * @dataProvider dataProperties * @param array $properties */ + #[DataProvider('dataProperties')] public function testProperties(string $className, array $properties): void { $reflectionProvider = self::createReflectionProvider(); diff --git a/tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php b/tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php index 73ca640269..b48fa67162 100644 --- a/tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php +++ b/tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php @@ -16,6 +16,8 @@ use PHPStan\Analyser\Scope; use PHPStan\Testing\PHPStanTestCase; use PHPStan\TrinaryLogic; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; class DeprecatedAnnotationsTest extends PHPStanTestCase @@ -88,9 +90,9 @@ public static function dataDeprecatedAnnotations(): array } /** - * @dataProvider dataDeprecatedAnnotations * @param array $deprecatedAnnotations */ + #[DataProvider('dataDeprecatedAnnotations')] public function testDeprecatedAnnotations(bool $deprecated, string $className, ?string $classDeprecation, array $deprecatedAnnotations): void { $reflectionProvider = self::createReflectionProvider(); @@ -189,10 +191,9 @@ public static function dataDeprecatedAttributeAboveFunction(): iterable } /** - * @dataProvider dataDeprecatedAttributeAboveFunction - * * @param non-empty-string $functionName */ + #[DataProvider('dataDeprecatedAttributeAboveFunction')] public function testDeprecatedAttributeAboveFunction(string $functionName, TrinaryLogic $isDeprecated, ?string $deprecatedDescription): void { require_once __DIR__ . '/data/deprecated-attribute-functions.php'; @@ -231,9 +232,7 @@ public static function dataDeprecatedAttributeAboveMethod(): iterable ]; } - /** - * @dataProvider dataDeprecatedAttributeAboveMethod - */ + #[DataProvider('dataDeprecatedAttributeAboveMethod')] public function testDeprecatedAttributeAboveMethod(string $className, string $methodName, TrinaryLogic $isDeprecated, ?string $deprecatedDescription): void { $reflectionProvider = self::createReflectionProvider(); @@ -294,9 +293,7 @@ public static function dataDeprecatedAttributeAboveClassConstant(): iterable ]; } - /** - * @dataProvider dataDeprecatedAttributeAboveClassConstant - */ + #[DataProvider('dataDeprecatedAttributeAboveClassConstant')] public function testDeprecatedAttributeAboveClassConstant(string $className, string $constantName, TrinaryLogic $isDeprecated, ?string $deprecatedDescription): void { $reflectionProvider = self::createReflectionProvider(); @@ -328,15 +325,10 @@ public static function dataDeprecatedAttributeAboveEnumCase(): iterable ]; } - /** - * @dataProvider dataDeprecatedAttributeAboveEnumCase - */ + #[RequiresPhp('>= 8.1')] + #[DataProvider('dataDeprecatedAttributeAboveEnumCase')] public function testDeprecatedAttributeAboveEnumCase(string $className, string $caseName, TrinaryLogic $isDeprecated, ?string $deprecatedDescription): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $reflectionProvider = self::createReflectionProvider(); $class = $reflectionProvider->getClass($className); $case = $class->getEnumCase($caseName); @@ -384,15 +376,12 @@ public static function dataDeprecatedAttributeAbovePropertyHook(): iterable } /** - * @dataProvider dataDeprecatedAttributeAbovePropertyHook * @param 'get'|'set' $hookName */ + #[RequiresPhp('>= 8.4')] + #[DataProvider('dataDeprecatedAttributeAbovePropertyHook')] public function testDeprecatedAttributeAbovePropertyHook(string $className, string $propertyName, string $hookName, TrinaryLogic $isDeprecated, ?string $deprecatedDescription): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $reflectionProvider = self::createReflectionProvider(); $class = $reflectionProvider->getClass($className); $property = $class->getNativeProperty($propertyName); diff --git a/tests/PHPStan/Reflection/Annotations/DeprecatedAttributePhpFunctionFromParserReflectionRuleTest.php b/tests/PHPStan/Reflection/Annotations/DeprecatedAttributePhpFunctionFromParserReflectionRuleTest.php index efdfaece70..aef982a7d7 100644 --- a/tests/PHPStan/Reflection/Annotations/DeprecatedAttributePhpFunctionFromParserReflectionRuleTest.php +++ b/tests/PHPStan/Reflection/Annotations/DeprecatedAttributePhpFunctionFromParserReflectionRuleTest.php @@ -10,8 +10,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function sprintf; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -112,12 +112,9 @@ public function testMethodRule(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPropertyHookRule(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/deprecated-attribute-property-hooks.php'], [ [ 'Not deprecated', diff --git a/tests/PHPStan/Reflection/Annotations/FinalAnnotationsTest.php b/tests/PHPStan/Reflection/Annotations/FinalAnnotationsTest.php index dd259efe7d..b24c82fba9 100644 --- a/tests/PHPStan/Reflection/Annotations/FinalAnnotationsTest.php +++ b/tests/PHPStan/Reflection/Annotations/FinalAnnotationsTest.php @@ -6,6 +6,7 @@ use FinalAnnotations\Foo; use PHPStan\Analyser\Scope; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class FinalAnnotationsTest extends PHPStanTestCase { @@ -37,9 +38,9 @@ public static function dataFinalAnnotations(): array } /** - * @dataProvider dataFinalAnnotations * @param array $finalAnnotations */ + #[DataProvider('dataFinalAnnotations')] public function testFinalAnnotations(bool $final, string $className, array $finalAnnotations): void { $reflectionProvider = self::createReflectionProvider(); diff --git a/tests/PHPStan/Reflection/Annotations/InternalAnnotationsTest.php b/tests/PHPStan/Reflection/Annotations/InternalAnnotationsTest.php index 330953011b..79017d46cb 100644 --- a/tests/PHPStan/Reflection/Annotations/InternalAnnotationsTest.php +++ b/tests/PHPStan/Reflection/Annotations/InternalAnnotationsTest.php @@ -11,6 +11,7 @@ use PhpParser\Node\Name; use PHPStan\Analyser\Scope; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class InternalAnnotationsTest extends PHPStanTestCase { @@ -110,9 +111,9 @@ public static function dataInternalAnnotations(): array } /** - * @dataProvider dataInternalAnnotations * @param array $internalAnnotations */ + #[DataProvider('dataInternalAnnotations')] public function testInternalAnnotations(bool $internal, string $className, array $internalAnnotations): void { $reflectionProvider = self::createReflectionProvider(); diff --git a/tests/PHPStan/Reflection/Annotations/ThrowsAnnotationsTest.php b/tests/PHPStan/Reflection/Annotations/ThrowsAnnotationsTest.php index eac3643c92..b58322ca01 100644 --- a/tests/PHPStan/Reflection/Annotations/ThrowsAnnotationsTest.php +++ b/tests/PHPStan/Reflection/Annotations/ThrowsAnnotationsTest.php @@ -6,6 +6,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use RuntimeException; use ThrowsAnnotations\BarTrait; use ThrowsAnnotations\Foo; @@ -68,9 +69,9 @@ public static function dataThrowsAnnotations(): array } /** - * @dataProvider dataThrowsAnnotations * @param array $throwsAnnotations */ + #[DataProvider('dataThrowsAnnotations')] public function testThrowsAnnotations(string $className, array $throwsAnnotations): void { $reflectionProvider = self::createReflectionProvider(); diff --git a/tests/PHPStan/Reflection/AttributeReflectionFromNodeRuleTest.php b/tests/PHPStan/Reflection/AttributeReflectionFromNodeRuleTest.php index 756ff9e1b1..a07cbead1b 100644 --- a/tests/PHPStan/Reflection/AttributeReflectionFromNodeRuleTest.php +++ b/tests/PHPStan/Reflection/AttributeReflectionFromNodeRuleTest.php @@ -11,10 +11,10 @@ use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Testing\RuleTestCase; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\RequiresPhp; use function count; use function implode; use function sprintf; -use const PHP_VERSION_ID; /** * @extends RuleTestCase> @@ -80,12 +80,9 @@ public function processNode(Node $node, Scope $scope): array }; } + #[RequiresPhp('>= 8.0')] public function testRule(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/attribute-reflection.php'], [ [ '#[AttributeReflectionTest\MyAttr(one: 7, two: 8)], $test: #[AttributeReflectionTest\MyAttr(one: 9, two: 10)]', diff --git a/tests/PHPStan/Reflection/AttributeReflectionTest.php b/tests/PHPStan/Reflection/AttributeReflectionTest.php index 65390743bb..2dda376cc0 100644 --- a/tests/PHPStan/Reflection/AttributeReflectionTest.php +++ b/tests/PHPStan/Reflection/AttributeReflectionTest.php @@ -7,6 +7,8 @@ use PhpParser\Node\Name; use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function count; use const PHP_VERSION_ID; @@ -148,19 +150,16 @@ public static function dataAttributeReflections(): iterable } /** - * @dataProvider dataAttributeReflections * @param list $attributeReflections * @param list}> $expectations */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataAttributeReflections')] public function testAttributeReflections( array $attributeReflections, array $expectations, ): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0'); - } - $this->assertCount(count($expectations), $attributeReflections); foreach ($expectations as $i => [$name, $argumentTypes]) { $attribute = $attributeReflections[$i]; diff --git a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php index 60bbd33ed0..06c9407908 100644 --- a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php +++ b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php @@ -8,6 +8,7 @@ use PHPStan\BetterReflection\Reflector\DefaultReflector; use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use TestDirectorySourceLocator\AFoo; use TestDirectorySourceLocator\EmptyClass; use function array_map; @@ -70,9 +71,7 @@ public static function dataClass(): iterable ]; } - /** - * @dataProvider dataClass - */ + #[DataProvider('dataClass')] public function testClass(string $className, string $expectedClassName, string $file): void { $factory = self::getContainer()->getByType(OptimizedDirectorySourceLocatorFactory::class); @@ -130,9 +129,7 @@ public static function dataFunctionExists(): array ]; } - /** - * @dataProvider dataFunctionExists - */ + #[DataProvider('dataFunctionExists')] public function testFunctionExists(string $functionName, string $expectedFunctionName, string $file): void { $factory = self::getContainer()->getByType(OptimizedDirectorySourceLocatorFactory::class); @@ -202,9 +199,7 @@ public static function dataConstant(): iterable ]; } - /** - * @dataProvider dataConstant - */ + #[DataProvider('dataConstant')] public function testConstant(string $constantName, ?string $expectedFile): void { $factory = self::getContainer()->getByType(OptimizedDirectorySourceLocatorFactory::class); @@ -298,9 +293,7 @@ public static function dataFunctionDoesNotExist(): array ]; } - /** - * @dataProvider dataFunctionDoesNotExist - */ + #[DataProvider('dataFunctionDoesNotExist')] public function testFunctionDoesNotExist(string $functionName): void { $factory = self::getContainer()->getByType(OptimizedDirectorySourceLocatorFactory::class); diff --git a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php index 0a918f64f0..f8c0875f69 100644 --- a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php +++ b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php @@ -10,6 +10,7 @@ use PHPStan\Reflection\InitializerExprTypeResolver; use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use SingleFileSourceLocatorTestClass; use TestSingleFileSourceLocator\AFoo; use function array_map; @@ -127,9 +128,7 @@ public static function dataForIdenifiersByType(): iterable ]; } - /** - * @dataProvider dataClass - */ + #[DataProvider('dataClass')] public function testClass(string $className, string $expectedClassName, string $file): void { $factory = self::getContainer()->getByType(OptimizedSingleFileSourceLocatorFactory::class); @@ -165,9 +164,7 @@ public static function dataFunction(): array ]; } - /** - * @dataProvider dataFunction - */ + #[DataProvider('dataFunction')] public function testFunction(string $functionName, string $expectedFunctionName, string $file): void { $factory = self::getContainer()->getByType(OptimizedSingleFileSourceLocatorFactory::class); @@ -203,9 +200,7 @@ public static function dataConst(): array ]; } - /** - * @dataProvider dataConst - */ + #[DataProvider('dataConst')] public function testConst(string $constantName, string $valueTypeDescription): void { $factory = self::getContainer()->getByType(OptimizedSingleFileSourceLocatorFactory::class); @@ -229,9 +224,7 @@ public static function dataConstUnknown(): array ]; } - /** - * @dataProvider dataConstUnknown - */ + #[DataProvider('dataConstUnknown')] public function testConstUnknown(string $constantName): void { $factory = self::getContainer()->getByType(OptimizedSingleFileSourceLocatorFactory::class); @@ -242,9 +235,9 @@ public function testConstUnknown(string $constantName): void } /** - * @dataProvider dataForIdenifiersByType * @param class-string[] $expectedIdentifiers */ + #[DataProvider('dataForIdenifiersByType')] public function testLocateIdentifiersByType( IdentifierType $identifierType, array $expectedIdentifiers, diff --git a/tests/PHPStan/Reflection/ClassReflectionPropertyHooksTest.php b/tests/PHPStan/Reflection/ClassReflectionPropertyHooksTest.php index 9910051305..80c75e06cf 100644 --- a/tests/PHPStan/Reflection/ClassReflectionPropertyHooksTest.php +++ b/tests/PHPStan/Reflection/ClassReflectionPropertyHooksTest.php @@ -2,33 +2,20 @@ namespace PHPStan\Reflection; -use Override; use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\IntegerType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function count; -use const PHP_VERSION_ID; +#[RequiresPhp('>= 8.4')] class ClassReflectionPropertyHooksTest extends PHPStanTestCase { - #[Override] - protected function setUp(): void - { - if (PHP_VERSION_ID >= 80400) { - return; - } - - self::markTestSkipped('Test requires PHP 8.4'); - } - public static function dataPropertyHooks(): iterable { - if (PHP_VERSION_ID < 80100) { - return []; - } - $reflectionProvider = self::createReflectionProvider(); yield [ @@ -334,10 +321,10 @@ public static function dataPropertyHooks(): iterable } /** - * @dataProvider dataPropertyHooks * @param ExtendedPropertyReflection::HOOK_* $hookName * @param string[] $parameterTypes */ + #[DataProvider('dataPropertyHooks')] public function testPropertyHooks( ClassReflection $classReflection, string $propertyName, diff --git a/tests/PHPStan/Reflection/ClassReflectionTest.php b/tests/PHPStan/Reflection/ClassReflectionTest.php index 61ef3654fd..8eba313bc3 100644 --- a/tests/PHPStan/Reflection/ClassReflectionTest.php +++ b/tests/PHPStan/Reflection/ClassReflectionTest.php @@ -30,12 +30,13 @@ use PHPStan\Testing\PHPStanTestCase; use PHPStan\Testing\RuleTestCase; use PHPStan\Type\IntegerType; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use PHPUnit\Framework\TestCase; use ReflectionClass; use WrongClassConstantFile\SecuredRouter; use function array_map; use function array_values; -use const PHP_VERSION_ID; class ClassReflectionTest extends PHPStanTestCase { @@ -50,9 +51,9 @@ public static function dataHasTraitUse(): array } /** - * @dataProvider dataHasTraitUse * @param class-string $className */ + #[DataProvider('dataHasTraitUse')] public function testHasTraitUse(string $className, bool $has): void { $reflectionProvider = self::createReflectionProvider(); @@ -93,10 +94,10 @@ public static function dataClassHierarchyDistances(): array } /** - * @dataProvider dataClassHierarchyDistances * @param class-string $class * @param int[] $expectedDistances */ + #[DataProvider('dataClassHierarchyDistances')] public function testClassHierarchyDistances( string $class, array $expectedDistances, @@ -169,9 +170,7 @@ public static function dataIsAttributeClass(): array ]; } - /** - * @dataProvider dataIsAttributeClass - */ + #[DataProvider('dataIsAttributeClass')] public function testIsAttributeClass(string $className, bool $expected, int $expectedFlags = Attribute::TARGET_ALL): void { $reflectionProvider = self::createReflectionProvider(); @@ -192,10 +191,10 @@ public function testDeprecatedConstantFromAnotherFile(): void } /** - * @dataProvider dataNestedRecursiveTraits * @param class-string $className * @param array $expected */ + #[DataProvider('dataNestedRecursiveTraits')] public function testGetTraits(string $className, array $expected, bool $recursive): void { $reflectionProvider = self::createReflectionProvider(); @@ -284,26 +283,22 @@ public static function dataNestedRecursiveTraits(): array ]; } + #[RequiresPhp('>= 8.1')] public function testEnumIsFinal(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $reflectionProvider = self::createReflectionProvider(); $enum = $reflectionProvider->getClass('PHPStan\Fixture\TestEnum'); $this->assertTrue($enum->isEnum()); - $this->assertInstanceOf('ReflectionEnum', $enum->getNativeReflection()); // @phpstan-ignore-line Exact error differs on PHP 7.4 and others + + // @phpstan-ignore-next-line Exact error differs on PHP 7.4 and others + $this->assertInstanceOf('ReflectionEnum', $enum->getNativeReflection()); $this->assertTrue($enum->isFinal()); $this->assertTrue($enum->isFinalByKeyword()); } + #[RequiresPhp('>= 8.1')] public function testBackedEnumType(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $reflectionProvider = self::createReflectionProvider(); $enum = $reflectionProvider->getClass('PHPStan\Fixture\TestEnum'); $this->assertInstanceOf(IntegerType::class, $enum->getBackedEnumType()); diff --git a/tests/PHPStan/Reflection/Constant/RuntimeConstantReflectionTest.php b/tests/PHPStan/Reflection/Constant/RuntimeConstantReflectionTest.php index 6d5e489c57..925cb4350d 100644 --- a/tests/PHPStan/Reflection/Constant/RuntimeConstantReflectionTest.php +++ b/tests/PHPStan/Reflection/Constant/RuntimeConstantReflectionTest.php @@ -5,6 +5,7 @@ use PhpParser\Node\Name; use PHPStan\Testing\PHPStanTestCase; use PHPStan\TrinaryLogic; +use PHPUnit\Framework\Attributes\DataProvider; use const PHP_VERSION_ID; class RuntimeConstantReflectionTest extends PHPStanTestCase @@ -41,9 +42,7 @@ public static function dataDeprecatedConstants(): iterable ]; } - /** - * @dataProvider dataDeprecatedConstants - */ + #[DataProvider('dataDeprecatedConstants')] public function testDeprecatedConstants(Name $constName, TrinaryLogic $isDeprecated, ?string $deprecationMessage): void { require_once __DIR__ . '/data/deprecated-constant.php'; diff --git a/tests/PHPStan/Reflection/Deprecation/DeprecationProviderTest.php b/tests/PHPStan/Reflection/Deprecation/DeprecationProviderTest.php index c52796550d..e88a5b66f6 100644 --- a/tests/PHPStan/Reflection/Deprecation/DeprecationProviderTest.php +++ b/tests/PHPStan/Reflection/Deprecation/DeprecationProviderTest.php @@ -15,29 +15,36 @@ use PHPStan\Analyser\ScopeContext; use PHPStan\Analyser\ScopeFactory; use PHPStan\Testing\PHPStanTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; class DeprecationProviderTest extends PHPStanTestCase { + #[RequiresPhp('>= 8.0')] public function testCustomDeprecations(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('PHP 8.0+ is required as CustomDeprecationProvider uses unions.'); - } - require __DIR__ . '/data/deprecations.php'; $reflectionProvider = self::createReflectionProvider(); $notDeprecatedClass = $reflectionProvider->getClass(NotDeprecatedClass::class); $attributeDeprecatedClass = $reflectionProvider->getClass(AttributeDeprecatedClass::class); - $phpDocDeprecatedClass = $reflectionProvider->getClass(PhpDocDeprecatedClass::class); // @phpstan-ignore classConstant.deprecatedClass - $phpDocDeprecatedClassWithMessages = $reflectionProvider->getClass(PhpDocDeprecatedClassWithMessage::class); // @phpstan-ignore classConstant.deprecatedClass + + // @phpstan-ignore classConstant.deprecatedClass + $phpDocDeprecatedClass = $reflectionProvider->getClass(PhpDocDeprecatedClass::class); + + // @phpstan-ignore classConstant.deprecatedClass + $phpDocDeprecatedClassWithMessages = $reflectionProvider->getClass(PhpDocDeprecatedClassWithMessage::class); $attributeDeprecatedClassWithMessages = $reflectionProvider->getClass(AttributeDeprecatedClassWithMessage::class); - $doubleDeprecatedClass = $reflectionProvider->getClass(DoubleDeprecatedClass::class); // @phpstan-ignore classConstant.deprecatedClass - $doubleDeprecatedClassOnlyPhpDocMessage = $reflectionProvider->getClass(DoubleDeprecatedClassOnlyPhpDocMessage::class); // @phpstan-ignore classConstant.deprecatedClass - $doubleDeprecatedClassOnlyAttributeMessage = $reflectionProvider->getClass(DoubleDeprecatedClassOnlyAttributeMessage::class); // @phpstan-ignore classConstant.deprecatedClass + + // @phpstan-ignore classConstant.deprecatedClass + $doubleDeprecatedClass = $reflectionProvider->getClass(DoubleDeprecatedClass::class); + + // @phpstan-ignore classConstant.deprecatedClass + $doubleDeprecatedClassOnlyPhpDocMessage = $reflectionProvider->getClass(DoubleDeprecatedClassOnlyPhpDocMessage::class); + + // @phpstan-ignore classConstant.deprecatedClass + $doubleDeprecatedClassOnlyAttributeMessage = $reflectionProvider->getClass(DoubleDeprecatedClassOnlyAttributeMessage::class); $notDeprecatedFunction = $reflectionProvider->getFunction(new FullyQualified('CustomDeprecations\\notDeprecatedFunction'), null); $phpDocDeprecatedFunction = $reflectionProvider->getFunction(new FullyQualified('CustomDeprecations\\phpDocDeprecatedFunction'), null); @@ -185,12 +192,9 @@ public function testCustomDeprecations(): void self::assertSame('attribute', $doubleDeprecatedFunctionOnlyAttributeMessage->getDeprecatedDescription()); } + #[RequiresPhp('>= 8.1')] public function testCustomDeprecationsOfEnumCases(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('PHP 8.1+ is required to test enums.'); - } - require __DIR__ . '/data/deprecations-enums.php'; $reflectionProvider = self::createReflectionProvider(); diff --git a/tests/PHPStan/Reflection/FunctionReflectionTest.php b/tests/PHPStan/Reflection/FunctionReflectionTest.php index f8f775f040..12dd5ee438 100644 --- a/tests/PHPStan/Reflection/FunctionReflectionTest.php +++ b/tests/PHPStan/Reflection/FunctionReflectionTest.php @@ -6,6 +6,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Testing\PHPStanTestCase; use PHPStan\TrinaryLogic; +use PHPUnit\Framework\Attributes\DataProvider; use const PHP_VERSION_ID; class FunctionReflectionTest extends PHPStanTestCase @@ -36,10 +37,9 @@ public static function dataPhpdocFunctions(): iterable } /** - * @dataProvider dataPhpdocFunctions - * * @param non-empty-string $functionName */ + #[DataProvider('dataPhpdocFunctions')] public function testFunctionHasPhpdoc(string $functionName, ?string $expectedDoc): void { require_once __DIR__ . '/data/function-with-phpdoc.php'; @@ -114,9 +114,7 @@ public static function dataPhpdocMethods(): iterable ]; } - /** - * @dataProvider dataPhpdocMethods - */ + #[DataProvider('dataPhpdocMethods')] public function testMethodHasPhpdoc(string $className, string $methodName, ?string $expectedDocComment): void { $reflectionProvider = self::createReflectionProvider(); @@ -142,9 +140,9 @@ public static function dataFunctionReturnsByReference(): iterable } /** - * @dataProvider dataFunctionReturnsByReference * @param non-empty-string $functionName */ + #[DataProvider('dataFunctionReturnsByReference')] public function testFunctionReturnsByReference(string $functionName, TrinaryLogic $expectedReturnsByRef): void { require_once __DIR__ . '/data/returns-by-reference.php'; @@ -177,9 +175,7 @@ public static function dataMethodReturnsByReference(): iterable yield ['ReturnsByReference\\E', 'cases', TrinaryLogic::createNo()]; } - /** - * @dataProvider dataMethodReturnsByReference - */ + #[DataProvider('dataMethodReturnsByReference')] public function testMethodReturnsByReference(string $className, string $methodName, TrinaryLogic $expectedReturnsByRef): void { $reflectionProvider = self::createReflectionProvider(); diff --git a/tests/PHPStan/Reflection/GenericParametersAcceptorResolverTest.php b/tests/PHPStan/Reflection/GenericParametersAcceptorResolverTest.php index fd935373e4..ea627a029f 100644 --- a/tests/PHPStan/Reflection/GenericParametersAcceptorResolverTest.php +++ b/tests/PHPStan/Reflection/GenericParametersAcceptorResolverTest.php @@ -17,6 +17,7 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function count; use function get_class; use function sprintf; @@ -422,9 +423,9 @@ public static function dataResolve(): array } /** - * @dataProvider dataResolve * @param Type[] $argTypes */ + #[DataProvider('dataResolve')] public function testResolve(array $argTypes, ParametersAcceptor $parametersAcceptor, ParametersAcceptor $expectedResult): void { self::getContainer(); // to initialize bleeding edge diff --git a/tests/PHPStan/Reflection/InitializerExprTypeResolverTest.php b/tests/PHPStan/Reflection/InitializerExprTypeResolverTest.php index f1d26f0240..6c3ba79cfb 100644 --- a/tests/PHPStan/Reflection/InitializerExprTypeResolverTest.php +++ b/tests/PHPStan/Reflection/InitializerExprTypeResolverTest.php @@ -10,6 +10,7 @@ use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\NeverType; use PHPStan\Type\Type; +use PHPUnit\Framework\Attributes\DataProvider; class InitializerExprTypeResolverTest extends PHPStanTestCase { @@ -100,11 +101,11 @@ static function (Expr $expr): Type { } /** - * @dataProvider dataExplicitNever * * @param class-string $resultClass * @param callable(Expr): Type $callback */ + #[DataProvider('dataExplicitNever')] public function testExplicitNever(Expr $left, Expr $right, callable $callback, string $resultClass, ?bool $resultIsExplicit = null): void { $initializerExprTypeResolver = self::getContainer()->getByType(InitializerExprTypeResolver::class); diff --git a/tests/PHPStan/Reflection/ParametersAcceptorSelectorTest.php b/tests/PHPStan/Reflection/ParametersAcceptorSelectorTest.php index 8c0da7277c..725c7c71e1 100644 --- a/tests/PHPStan/Reflection/ParametersAcceptorSelectorTest.php +++ b/tests/PHPStan/Reflection/ParametersAcceptorSelectorTest.php @@ -28,6 +28,7 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function count; class ParametersAcceptorSelectorTest extends PHPStanTestCase @@ -423,10 +424,10 @@ public static function dataSelectFromTypes(): Generator } /** - * @dataProvider dataSelectFromTypes * @param Type[] $types * @param ParametersAcceptor[] $variants */ + #[DataProvider('dataSelectFromTypes')] public function testSelectFromTypes( array $types, array $variants, diff --git a/tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php b/tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php index 10bc3be273..c9f990d1cd 100644 --- a/tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php +++ b/tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php @@ -13,6 +13,7 @@ use PHPStan\ShouldNotHappenException; use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use ReflectionClass; use Symfony\Component\Finder\Finder; use Throwable; @@ -64,7 +65,7 @@ public static function data(): iterable } } - /** @dataProvider data */ + #[DataProvider('data')] public function test(string $input, string $expectedOutput): void { $output = self::generateSymbolDescription($input); diff --git a/tests/PHPStan/Reflection/ReflectionProviderTest.php b/tests/PHPStan/Reflection/ReflectionProviderTest.php index 1e735312c6..2e538e5f32 100644 --- a/tests/PHPStan/Reflection/ReflectionProviderTest.php +++ b/tests/PHPStan/Reflection/ReflectionProviderTest.php @@ -9,6 +9,8 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; class ReflectionProviderTest extends PHPStanTestCase @@ -50,10 +52,9 @@ public static function dataFunctionThrowType(): iterable } /** - * @dataProvider dataFunctionThrowType - * * @param non-empty-string $functionName */ + #[DataProvider('dataFunctionThrowType')] public function testFunctionThrowType(string $functionName, ?Type $expectedThrowType): void { $reflectionProvider = self::createReflectionProvider(); @@ -97,10 +98,9 @@ public static function dataFunctionDeprecated(): iterable } /** - * @dataProvider dataFunctionDeprecated - * * @param non-empty-string $functionName */ + #[DataProvider('dataFunctionDeprecated')] public function testFunctionDeprecated(string $functionName, bool $isDeprecated): void { $reflectionProvider = self::createReflectionProvider(); @@ -124,9 +124,7 @@ public static function dataMethodThrowType(): array ]; } - /** - * @dataProvider dataMethodThrowType - */ + #[DataProvider('dataMethodThrowType')] public function testMethodThrowType(string $className, string $methodName, ?Type $expectedThrowType): void { $reflectionProvider = self::createReflectionProvider(); @@ -144,12 +142,9 @@ public function testMethodThrowType(string $className, string $methodName, ?Type ); } + #[RequiresPhp('>= 8.3')] public function testNativeClassConstantTypeInEvaledClass(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - eval('namespace NativeClassConstantInEvaledClass; class Foo { public const int FOO = 1; }'); $reflectionProvider = self::createReflectionProvider(); diff --git a/tests/PHPStan/Reflection/SignatureMap/Php8SignatureMapProviderTest.php b/tests/PHPStan/Reflection/SignatureMap/Php8SignatureMapProviderTest.php index 99c5be4eb3..8c422e1500 100644 --- a/tests/PHPStan/Reflection/SignatureMap/Php8SignatureMapProviderTest.php +++ b/tests/PHPStan/Reflection/SignatureMap/Php8SignatureMapProviderTest.php @@ -34,6 +34,7 @@ use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; use PHPStan\Type\VoidType; +use PHPUnit\Framework\Attributes\DataProvider; use function array_map; use function array_merge; use function count; @@ -132,9 +133,9 @@ public static function dataFunctions(): array } /** - * @dataProvider dataFunctions * @param mixed[] $parameters */ + #[DataProvider('dataFunctions')] public function testFunctions( string $functionName, array $parameters, @@ -262,9 +263,9 @@ public static function dataMethods(): array } /** - * @dataProvider dataMethods * @param mixed[] $parameters */ + #[DataProvider('dataMethods')] public function testMethods( string $className, string $methodName, @@ -313,9 +314,7 @@ public static function dataParseAll(): array return array_map(static fn (string $file): array => [__DIR__ . '/../../../../vendor/phpstan/php-8-stubs/' . $file], array_merge($map->classes, $map->functions)); } - /** - * @dataProvider dataParseAll - */ + #[DataProvider('dataParseAll')] public function testParseAll(string $stubFile): void { $parser = $this->getParser(); diff --git a/tests/PHPStan/Reflection/SignatureMap/SignatureMapParserTest.php b/tests/PHPStan/Reflection/SignatureMap/SignatureMapParserTest.php index b4bb8924d4..98b47e6cb0 100644 --- a/tests/PHPStan/Reflection/SignatureMap/SignatureMapParserTest.php +++ b/tests/PHPStan/Reflection/SignatureMap/SignatureMapParserTest.php @@ -28,6 +28,7 @@ use PHPStan\Type\StringType; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use ReflectionParameter; use Throwable; use function array_keys; @@ -424,9 +425,9 @@ public static function dataGetFunctions(): array } /** - * @dataProvider dataGetFunctions * @param mixed[] $map */ + #[DataProvider('dataGetFunctions')] public function testGetFunctions( array $map, ?string $className, @@ -490,9 +491,7 @@ public static function dataParseAll(): array ]; } - /** - * @dataProvider dataParseAll - */ + #[DataProvider('dataParseAll')] public function testParseAll(int $phpVersionId): void { $parser = self::getContainer()->getByType(SignatureMapParser::class); diff --git a/tests/PHPStan/Rules/Api/ApiRuleHelperTest.php b/tests/PHPStan/Rules/Api/ApiRuleHelperTest.php index 6e43a9047e..81945b88e6 100644 --- a/tests/PHPStan/Rules/Api/ApiRuleHelperTest.php +++ b/tests/PHPStan/Rules/Api/ApiRuleHelperTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Rules\Api; use PHPStan\Analyser\Scope; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class ApiRuleHelperTest extends TestCase @@ -133,9 +134,7 @@ public static function dataIsPhpStanCode(): array ]; } - /** - * @dataProvider dataIsPhpStanCode - */ + #[DataProvider('dataIsPhpStanCode')] public function testIsPhpStanCode( ?string $scopeNamespace, string $scopeFile, diff --git a/tests/PHPStan/Rules/Arrays/ArrayDestructuringRuleTest.php b/tests/PHPStan/Rules/Arrays/ArrayDestructuringRuleTest.php index 19de8cfb95..b105abcd36 100644 --- a/tests/PHPStan/Rules/Arrays/ArrayDestructuringRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/ArrayDestructuringRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -49,12 +49,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/array-destructuring-nullsafe.php'], [ [ 'Cannot use array destructuring on array|null.', diff --git a/tests/PHPStan/Rules/Arrays/ArrayUnpackingRuleTest.php b/tests/PHPStan/Rules/Arrays/ArrayUnpackingRuleTest.php index 54f7d19336..826d3e33f1 100644 --- a/tests/PHPStan/Rules/Arrays/ArrayUnpackingRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/ArrayUnpackingRuleTest.php @@ -6,7 +6,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -26,12 +27,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('< 8.1')] public function testRule(): void { - if (PHP_VERSION_ID >= 80100) { - $this->markTestSkipped('Test requires PHP version <= 8.0'); - } - $this->checkUnions = true; $this->checkBenevolentUnions = true; $this->analyse([__DIR__ . '/data/array-unpacking.php'], [ @@ -70,12 +68,9 @@ public function testRule(): void ]); } + #[RequiresPhp('< 8.1')] public function testRuleDoNotCheckBenevolentUnion(): void { - if (PHP_VERSION_ID >= 80100) { - $this->markTestSkipped('Test requires PHP version <= 8.0'); - } - $this->checkUnions = true; $this->analyse([__DIR__ . '/data/array-unpacking.php'], [ [ @@ -97,12 +92,9 @@ public function testRuleDoNotCheckBenevolentUnion(): void ]); } + #[RequiresPhp('< 8.1')] public function testRuleDoNotCheckUnions(): void { - if (PHP_VERSION_ID >= 80100) { - $this->markTestSkipped('Test requires PHP version <= 8.0'); - } - $this->checkUnions = false; $this->analyse([__DIR__ . '/data/array-unpacking.php'], [ [ @@ -124,15 +116,10 @@ public static function dataRuleOnPHP81(): array ]; } - /** - * @dataProvider dataRuleOnPHP81 - */ + #[RequiresPhp('>= 8.1')] + #[DataProvider('dataRuleOnPHP81')] public function testRuleOnPHP81(bool $checkUnions): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1+'); - } - $this->checkUnions = $checkUnions; $this->analyse([__DIR__ . '/data/array-unpacking.php'], []); } diff --git a/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayDimFetchRuleTest.php index 48cfbdbef0..0d42bca9e9 100644 --- a/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayDimFetchRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -61,12 +61,9 @@ public function testInvalidKey(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug6315(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-6315.php'], [ [ 'Invalid array key type Bug6315\FooEnum::A.', diff --git a/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayItemRuleTest.php b/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayItemRuleTest.php index 7a40122d1c..ab486eeacf 100644 --- a/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayItemRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/InvalidKeyInArrayItemRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -63,12 +63,9 @@ public function testInvalidKeyShortArray(): void ]); } + #[RequiresPhp('>= 8.1')] public function testInvalidKeyEnum(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/invalid-key-array-item-enum.php'], [ [ 'Invalid array key type InvalidKeyArrayItemEnum\FooEnum::A.', diff --git a/tests/PHPStan/Rules/Arrays/IterableInForeachRuleTest.php b/tests/PHPStan/Rules/Arrays/IterableInForeachRuleTest.php index e3f89bc1d6..f392ac3202 100644 --- a/tests/PHPStan/Rules/Arrays/IterableInForeachRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/IterableInForeachRuleTest.php @@ -5,9 +5,10 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_merge; use function usort; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -58,12 +59,9 @@ public function testBug5744(): void ]); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = true; $this->analyse([__DIR__ . '/data/foreach-iterable-nullsafe.php'], [ [ @@ -130,15 +128,12 @@ public static function dataMixed(): array } /** - * @dataProvider dataMixed * @param list $errors */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataMixed')] public function testMixed(bool $checkExplicitMixed, bool $checkImplicitMixed, array $errors): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = $checkExplicitMixed; $this->checkImplicitMixed = $checkImplicitMixed; $this->analyse([__DIR__ . '/data/foreach-mixed.php'], $errors); diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index 18f8417247..a481085088 100644 --- a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php @@ -5,6 +5,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -341,12 +343,9 @@ public function testBug5744(): void ]); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/nonexistent-offset-nullsafe.php'], [ [ 'Offset 1 does not exist on array{a: int}.', @@ -375,12 +374,9 @@ public function testBug6379(): void $this->analyse([__DIR__ . '/data/bug-6379.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug4885(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-4885.php'], []); } @@ -484,12 +480,9 @@ public function testBug7469(): void $this->analyse([__DIR__ . '/data/bug-7469.php'], $expected); } + #[RequiresPhp('>= 8.1')] public function testBug7763(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-7763.php'], []); } @@ -612,12 +605,9 @@ public function testBug10926(): void ]); } + #[RequiresPhp('>= 8.0')] public function testMixed(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = true; $this->checkImplicitMixed = true; $this->analyse([__DIR__ . '/data/offset-access-mixed.php'], [ @@ -698,9 +688,9 @@ public static function dataReportPossiblyNonexistentArrayOffset(): iterable } /** - * @dataProvider dataReportPossiblyNonexistentArrayOffset * @param list $errors */ + #[DataProvider('dataReportPossiblyNonexistentArrayOffset')] public function testReportPossiblyNonexistentArrayOffset(bool $reportPossiblyNonexistentGeneralArrayOffset, bool $reportPossiblyNonexistentConstantArrayOffset, array $errors): void { $this->reportPossiblyNonexistentGeneralArrayOffset = $reportPossiblyNonexistentGeneralArrayOffset; @@ -764,11 +754,9 @@ public function testInternalClassesWithOverloadedOffsetAccess(): void $this->analyse([__DIR__ . '/data/internal-classes-overload-offset-access.php'], []); } + #[RequiresPhp('>= 8.4')] public function testInternalClassesWithOverloadedOffsetAccess84(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } $this->analyse([__DIR__ . '/data/internal-classes-overload-offset-access-php84.php'], []); } @@ -777,11 +765,9 @@ public function testInternalClassesWithOverloadedOffsetAccessInvalid(): void $this->analyse([__DIR__ . '/data/internal-classes-overload-offset-access-invalid.php'], []); } + #[RequiresPhp('>= 8.4')] public function testInternalClassesWithOverloadedOffsetAccessInvalid84(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } $this->analyse([__DIR__ . '/data/internal-classes-overload-offset-access-invalid-php84.php'], []); } diff --git a/tests/PHPStan/Rules/Arrays/OffsetAccessAssignOpRuleTest.php b/tests/PHPStan/Rules/Arrays/OffsetAccessAssignOpRuleTest.php index a2bfa6c29e..1c32d81285 100644 --- a/tests/PHPStan/Rules/Arrays/OffsetAccessAssignOpRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/OffsetAccessAssignOpRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -38,12 +38,9 @@ public function testRuleWithoutUnions(): void $this->analyse([__DIR__ . '/data/offset-access-assignop.php'], []); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkUnions = true; $this->analyse([__DIR__ . '/data/offset-access-assignop-nullsafe.php'], []); } diff --git a/tests/PHPStan/Rules/Arrays/OffsetAccessAssignmentRuleTest.php b/tests/PHPStan/Rules/Arrays/OffsetAccessAssignmentRuleTest.php index 542d2d00c5..1c78cb3f23 100644 --- a/tests/PHPStan/Rules/Arrays/OffsetAccessAssignmentRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/OffsetAccessAssignmentRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -129,12 +129,9 @@ public function testAssignNewOffsetToStubbedClass(): void $this->analyse([__DIR__ . '/data/new-offset-stub.php'], []); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkUnionTypes = true; $this->analyse([__DIR__ . '/data/offset-access-assignment-nullsafe.php'], [ [ diff --git a/tests/PHPStan/Rules/Arrays/OffsetAccessValueAssignmentRuleTest.php b/tests/PHPStan/Rules/Arrays/OffsetAccessValueAssignmentRuleTest.php index c95ffe9668..4c9b910bad 100644 --- a/tests/PHPStan/Rules/Arrays/OffsetAccessValueAssignmentRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/OffsetAccessValueAssignmentRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -52,12 +52,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/offset-access-value-assignment-nullsafe.php'], [ [ 'ArrayAccess does not accept int|null.', @@ -66,12 +63,9 @@ public function testRuleWithNullsafeVariant(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug5655b(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-5655b.php'], []); } diff --git a/tests/PHPStan/Rules/Arrays/UnpackIterableInArrayRuleTest.php b/tests/PHPStan/Rules/Arrays/UnpackIterableInArrayRuleTest.php index f737cf7567..ce675567f2 100644 --- a/tests/PHPStan/Rules/Arrays/UnpackIterableInArrayRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/UnpackIterableInArrayRuleTest.php @@ -5,9 +5,10 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_merge; use function usort; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -42,12 +43,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/unpack-iterable-nullsafe.php'], [ [ 'Only iterables can be unpacked, array|null given.', @@ -102,15 +100,12 @@ public static function dataMixed(): array } /** - * @dataProvider dataMixed * @param list $errors */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataMixed')] public function testMixed(bool $checkExplicitMixed, bool $checkImplicitMixed, array $errors): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = $checkExplicitMixed; $this->checkImplicitMixed = $checkImplicitMixed; $this->analyse([__DIR__ . '/data/unpack-mixed.php'], $errors); diff --git a/tests/PHPStan/Rules/Cast/EchoRuleTest.php b/tests/PHPStan/Rules/Cast/EchoRuleTest.php index 52f97eff32..4072e82b0d 100644 --- a/tests/PHPStan/Rules/Cast/EchoRuleTest.php +++ b/tests/PHPStan/Rules/Cast/EchoRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -54,12 +54,9 @@ public function testEchoRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/echo-nullsafe.php'], [ [ 'Parameter #1 (array|null) of echo cannot be converted to string.', diff --git a/tests/PHPStan/Rules/Cast/InvalidCastRuleTest.php b/tests/PHPStan/Rules/Cast/InvalidCastRuleTest.php index 032945b37d..cad88fb000 100644 --- a/tests/PHPStan/Rules/Cast/InvalidCastRuleTest.php +++ b/tests/PHPStan/Rules/Cast/InvalidCastRuleTest.php @@ -5,9 +5,10 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_merge; use function usort; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -60,12 +61,9 @@ public function testBug5162(): void $this->analyse([__DIR__ . '/data/bug-5162.php'], []); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/invalid-cast-nullsafe.php'], [ [ 'Cannot cast stdClass|null to string.', @@ -158,15 +156,12 @@ public static function dataMixed(): array } /** - * @dataProvider dataMixed * @param list $errors */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataMixed')] public function testMixed(bool $checkExplicitMixed, bool $checkImplicitMixed, array $errors): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkImplicitMixed = $checkImplicitMixed; $this->checkExplicitMixed = $checkExplicitMixed; $this->analyse([__DIR__ . '/data/mixed-cast.php'], $errors); diff --git a/tests/PHPStan/Rules/Cast/InvalidPartOfEncapsedStringRuleTest.php b/tests/PHPStan/Rules/Cast/InvalidPartOfEncapsedStringRuleTest.php index 6df6e84e92..b42c44cd09 100644 --- a/tests/PHPStan/Rules/Cast/InvalidPartOfEncapsedStringRuleTest.php +++ b/tests/PHPStan/Rules/Cast/InvalidPartOfEncapsedStringRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -33,12 +33,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/invalid-encapsed-part-nullsafe.php'], [ [ 'Part $bar?->obj (stdClass|null) of encapsed string cannot be cast to string.', diff --git a/tests/PHPStan/Rules/Cast/PrintRuleTest.php b/tests/PHPStan/Rules/Cast/PrintRuleTest.php index e4d1f4811a..509ab75570 100644 --- a/tests/PHPStan/Rules/Cast/PrintRuleTest.php +++ b/tests/PHPStan/Rules/Cast/PrintRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -54,12 +54,9 @@ public function testPrintRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/print-nullsafe.php'], [ [ 'Parameter array|null of print cannot be converted to string.', diff --git a/tests/PHPStan/Rules/Cast/UnsetCastRuleTest.php b/tests/PHPStan/Rules/Cast/UnsetCastRuleTest.php index 5794d64380..db6263ec9d 100644 --- a/tests/PHPStan/Rules/Cast/UnsetCastRuleTest.php +++ b/tests/PHPStan/Rules/Cast/UnsetCastRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @extends RuleTestCase @@ -39,9 +40,9 @@ public static function dataRule(): array } /** - * @dataProvider dataRule * @param list $errors */ + #[DataProvider('dataRule')] public function testRule(int $phpVersion, array $errors): void { $this->phpVersion = $phpVersion; diff --git a/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php b/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php index 8c3a2c9911..5da8aa72ea 100644 --- a/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php @@ -13,7 +13,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -118,12 +118,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testRuleForEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/enum-attributes.php'], [ [ 'Attribute class EnumAttributes\AttributeWithPropertyTarget does not have the class target.', @@ -151,12 +148,9 @@ public function testAllowDynamicPropertiesAttribute(): void $this->analyse([__DIR__ . '/data/allow-dynamic-properties-attribute.php'], []); } + #[RequiresPhp('>= 8.3')] public function testBug12011(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->checkExplicitMixed = true; $this->checkImplicitMixed = true; $this->analyse([__DIR__ . '/data/bug-12011.php'], [ @@ -167,12 +161,9 @@ public function testBug12011(): void ]); } + #[RequiresPhp('>= 8.2')] public function testBug12281(): void { - if (PHP_VERSION_ID < 80200) { - $this->markTestSkipped('Test requires PHP 8.2.'); - } - $this->checkExplicitMixed = true; $this->checkImplicitMixed = true; $this->analyse([__DIR__ . '/data/bug-12281.php'], [ diff --git a/tests/PHPStan/Rules/Classes/ClassConstantRuleTest.php b/tests/PHPStan/Rules/Classes/ClassConstantRuleTest.php index 706c635dc8..3ecc4572f9 100644 --- a/tests/PHPStan/Rules/Classes/ClassConstantRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ClassConstantRuleTest.php @@ -9,6 +9,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -238,9 +240,9 @@ public static function dataClassConstantOnExpression(): array } /** - * @dataProvider dataClassConstantOnExpression * @param list $errors */ + #[DataProvider('dataClassConstantOnExpression')] public function testClassConstantOnExpression(int $phpVersion, array $errors): void { $this->phpVersion = $phpVersion; @@ -282,12 +284,9 @@ public function testAttributes(): void ]); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->phpVersion = PHP_VERSION_ID; $this->analyse([__DIR__ . '/data/class-constant-nullsafe.php'], []); } @@ -422,12 +421,9 @@ public function testPhpstanInternalClass(): void ]); } + #[RequiresPhp('>= 8.2')] public function testClassConstantAccessedOnTrait(): void { - if (PHP_VERSION_ID < 80200) { - $this->markTestSkipped('Test requires PHP 8.2.'); - } - $this->phpVersion = PHP_VERSION_ID; $this->analyse([__DIR__ . '/data/class-constant-accessed-on-trait.php'], [ [ @@ -437,12 +433,9 @@ public function testClassConstantAccessedOnTrait(): void ]); } + #[RequiresPhp('>= 8.3')] public function testDynamicAccess(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->phpVersion = PHP_VERSION_ID; $this->analyse([__DIR__ . '/data/dynamic-constant-access.php'], [ diff --git a/tests/PHPStan/Rules/Classes/DuplicateDeclarationRuleTest.php b/tests/PHPStan/Rules/Classes/DuplicateDeclarationRuleTest.php index 5390b57ac9..c0f21a6053 100644 --- a/tests/PHPStan/Rules/Classes/DuplicateDeclarationRuleTest.php +++ b/tests/PHPStan/Rules/Classes/DuplicateDeclarationRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -66,12 +66,9 @@ public function testDuplicatePromotedProperty(): void ]); } + #[RequiresPhp('>= 8.1')] public function testDuplicateEnumCase(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/duplicate-enum-cases.php'], [ [ 'Cannot redeclare enum case DuplicatedEnumCase\Foo::BAR.', diff --git a/tests/PHPStan/Rules/Classes/EnumSanityRuleTest.php b/tests/PHPStan/Rules/Classes/EnumSanityRuleTest.php index af02a79635..22bb10a00e 100644 --- a/tests/PHPStan/Rules/Classes/EnumSanityRuleTest.php +++ b/tests/PHPStan/Rules/Classes/EnumSanityRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -17,12 +17,9 @@ protected function getRule(): Rule return new EnumSanityRule(); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1'); - } - $expected = [ /*[ // reported by AbstractMethodInNonAbstractClassRule @@ -110,12 +107,9 @@ public function testRule(): void $this->analyse([__DIR__ . '/data/enum-sanity.php'], $expected); } + #[RequiresPhp('>= 8.1')] public function testBug9402(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/bug-9402.php'], [ [ 'Enum case Bug9402\Foo::Two value \'foo\' does not match the "int" type.', @@ -124,12 +118,9 @@ public function testBug9402(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug11592(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/bug-11592.php'], [ [ 'Enum Bug11592\Test2 cannot redeclare native method cases().', diff --git a/tests/PHPStan/Rules/Classes/ExistingClassInClassExtendsRuleTest.php b/tests/PHPStan/Rules/Classes/ExistingClassInClassExtendsRuleTest.php index 18ed77fe2a..4ae78ffe28 100644 --- a/tests/PHPStan/Rules/Classes/ExistingClassInClassExtendsRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ExistingClassInClassExtendsRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\ClassNameCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -81,12 +81,9 @@ public function testFinalByTag(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/class-extends-enum.php'], [ [ 'Class ClassExtendsEnum\Foo extends enum ClassExtendsEnum\FooEnum.', @@ -132,12 +129,9 @@ public function testPhpstanInternalClass(): void ]); } + #[RequiresPhp('>= 8.2')] public function testReadonly(): void { - if (PHP_VERSION_ID < 80200) { - $this->markTestSkipped('This test needs PHP 8.2'); - } - $this->analyse([__DIR__ . '/data/extends-readonly-class.php'], [ [ 'Readonly class ExtendsReadOnlyClass\Foo extends non-readonly class ExtendsReadOnlyClass\Nonreadonly.', diff --git a/tests/PHPStan/Rules/Classes/ExistingClassInInstanceOfRuleTest.php b/tests/PHPStan/Rules/Classes/ExistingClassInInstanceOfRuleTest.php index e173d63ea6..2045a7d496 100644 --- a/tests/PHPStan/Rules/Classes/ExistingClassInInstanceOfRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ExistingClassInInstanceOfRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\ClassNameCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -76,12 +76,9 @@ public function testClassExists(): void $this->analyse([__DIR__ . '/data/instanceof-class-exists.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug7720(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-7720.php'], [ [ 'Instanceof between mixed and trait Bug7720\FooBar will always evaluate to false.', diff --git a/tests/PHPStan/Rules/Classes/ExistingClassInTraitUseRuleTest.php b/tests/PHPStan/Rules/Classes/ExistingClassInTraitUseRuleTest.php index 99ec0cab8d..a605490cfc 100644 --- a/tests/PHPStan/Rules/Classes/ExistingClassInTraitUseRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ExistingClassInTraitUseRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\ClassNameCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -72,12 +72,9 @@ public function testTraitUseError(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/trait-use-enum.php'], [ [ 'Class TraitUseEnum\Foo uses enum TraitUseEnum\FooEnum.', diff --git a/tests/PHPStan/Rules/Classes/ExistingClassesInClassImplementsRuleTest.php b/tests/PHPStan/Rules/Classes/ExistingClassesInClassImplementsRuleTest.php index ab88558cae..c3aea0595c 100644 --- a/tests/PHPStan/Rules/Classes/ExistingClassesInClassImplementsRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ExistingClassesInClassImplementsRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\ClassNameCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -63,12 +63,9 @@ public function testRuleImplementsError(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/class-implements-enum.php'], [ [ 'Class ClassImplementsEnum\Foo implements enum ClassImplementsEnum\FooEnum.', diff --git a/tests/PHPStan/Rules/Classes/ExistingClassesInEnumImplementsRuleTest.php b/tests/PHPStan/Rules/Classes/ExistingClassesInEnumImplementsRuleTest.php index 1164d86b77..98bf1f3608 100644 --- a/tests/PHPStan/Rules/Classes/ExistingClassesInEnumImplementsRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ExistingClassesInEnumImplementsRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\ClassNameCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -31,12 +31,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/enum-implements.php'], [ [ 'Interface EnumImplements\FooInterface referenced with incorrect case: EnumImplements\FOOInterface.', diff --git a/tests/PHPStan/Rules/Classes/ExistingClassesInInterfaceExtendsRuleTest.php b/tests/PHPStan/Rules/Classes/ExistingClassesInInterfaceExtendsRuleTest.php index e372d75d1e..18ecc90324 100644 --- a/tests/PHPStan/Rules/Classes/ExistingClassesInInterfaceExtendsRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ExistingClassesInInterfaceExtendsRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\ClassNameCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -59,12 +59,9 @@ public function testRuleExtendsError(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/interface-extends-enum.php'], [ [ 'Interface InterfaceExtendsEnum\Foo extends enum InterfaceExtendsEnum\FooEnum.', diff --git a/tests/PHPStan/Rules/Classes/ImpossibleInstanceOfRuleTest.php b/tests/PHPStan/Rules/Classes/ImpossibleInstanceOfRuleTest.php index c66cf737b7..ffddab32c4 100644 --- a/tests/PHPStan/Rules/Classes/ImpossibleInstanceOfRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ImpossibleInstanceOfRuleTest.php @@ -4,7 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -261,12 +262,9 @@ public function testBug5333(): void $this->analyse([__DIR__ . '/data/bug-5333.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug8042(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('This test needs PHP 8.0'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-8042.php'], [ [ @@ -282,12 +280,9 @@ public function testBug8042(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug7721(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-7721.php'], []); } @@ -465,9 +460,9 @@ public static function dataReportAlwaysTrueInLastCondition(): iterable } /** - * @dataProvider dataReportAlwaysTrueInLastCondition * @param list $expectedErrors */ + #[DataProvider('dataReportAlwaysTrueInLastCondition')] public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void { $this->treatPhpDocTypesAsCertain = true; @@ -475,12 +470,9 @@ public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLast $this->analyse([__DIR__ . '/data/impossible-instanceof-report-always-true-last-condition.php'], $expectedErrors); } + #[RequiresPhp('>= 8.1')] public function testBug10201(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-10201.php'], [ [ @@ -504,12 +496,9 @@ public function testBug3632(): void ]); } + #[RequiresPhp('>= 8.0')] public function testNewIsAlwaysFinalClass(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('This test needs PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/impossible-instanceof-new-is-always-final.php'], [ [ diff --git a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php index efacea58d5..05cec9b2c2 100644 --- a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php +++ b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php @@ -12,7 +12,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -231,12 +231,9 @@ public function testBug3404(): void ]); } + #[RequiresPhp('>= 8.0')] public function testOldStyleConstructorOnPhp8(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/php80-constructor.php'], [ [ 'Class OldStyleConstructorOnPhp8 does not have a constructor and must be instantiated without any parameters.', @@ -249,12 +246,9 @@ public function testOldStyleConstructorOnPhp8(): void ]); } + #[RequiresPhp('< 8.0')] public function testOldStyleConstructorOnPhp7(): void { - if (PHP_VERSION_ID >= 80000) { - $this->markTestSkipped('Test requires PHP 7.x'); - } - $this->analyse([__DIR__ . '/data/php80-constructor.php'], [ [ 'Class OldStyleConstructorOnPhp8 constructor invoked with 0 parameters, 1 required.', @@ -291,12 +285,9 @@ public function testBug4056(): void $this->analyse([__DIR__ . '/data/bug-4056.php'], []); } + #[RequiresPhp('>= 8.0')] public function testNamedArguments(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/instantiation-named-arguments.php'], [ [ 'Missing parameter $j (int) in call to InstantiationNamedArguments\Foo constructor.', @@ -353,22 +344,16 @@ public function testBug4681(): void $this->analyse([__DIR__ . '/data/bug-4681.php'], []); } + #[RequiresPhp('>= 8.1')] public function testFirstClassCallable(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1 and static reflection.'); - } - // handled by a different rule $this->analyse([__DIR__ . '/data/first-class-instantiation-callable.php'], []); } + #[RequiresPhp('>= 8.1')] public function testEnumInstantiation(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/enum-instantiation.php'], [ [ 'Cannot instantiate enum EnumInstantiation\Foo.', @@ -395,21 +380,15 @@ public function testBug6370(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug5553(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-5553.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug7048(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-7048.php'], [ [ 'Unknown parameter $recurrences in call to DatePeriod constructor.', @@ -438,12 +417,9 @@ public function testBug7048(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug7594(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-7594.php'], []); } @@ -506,12 +482,9 @@ public function testBug10248(): void $this->analyse([__DIR__ . '/data/bug-10248.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug11815(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/bug-11815.php'], []); } @@ -567,12 +540,9 @@ public function testInternalConstructor(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug12951(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1'); - } - require_once __DIR__ . '/../InternalTag/data/bug-12951-define.php'; $this->analyse([__DIR__ . '/../InternalTag/data/bug-12951-constructor.php'], [ [ @@ -586,12 +556,9 @@ public function testBug12951(): void ]); } + #[RequiresPhp('>= 8.0')] public function testNamedArgumentsPhpversion(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/named-arguments-phpversion.php'], []); } diff --git a/tests/PHPStan/Rules/Classes/InvalidPromotedPropertiesRuleTest.php b/tests/PHPStan/Rules/Classes/InvalidPromotedPropertiesRuleTest.php index 2ce3e7e268..f58e3fa475 100644 --- a/tests/PHPStan/Rules/Classes/InvalidPromotedPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Classes/InvalidPromotedPropertiesRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -94,22 +94,16 @@ public function testSupportedOnPhp8(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug9577(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->phpVersion = 80100; $this->analyse([__DIR__ . '/data/bug-9577.php'], []); } + #[RequiresPhp('>= 8.1')] public function testHooks(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->phpVersion = 80100; $this->analyse([__DIR__ . '/data/invalid-hooked-properties.php'], [ [ diff --git a/tests/PHPStan/Rules/Classes/LocalTypeAliasesRuleTest.php b/tests/PHPStan/Rules/Classes/LocalTypeAliasesRuleTest.php index 1105fcf3d4..b08d3804bf 100644 --- a/tests/PHPStan/Rules/Classes/LocalTypeAliasesRuleTest.php +++ b/tests/PHPStan/Rules/Classes/LocalTypeAliasesRuleTest.php @@ -11,7 +11,7 @@ use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -148,12 +148,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/local-type-aliases-enums.php'], [ [ 'Cannot import type alias Test: class LocalTypeAliasesEnums\NonexistentClass does not exist.', diff --git a/tests/PHPStan/Rules/Classes/MethodTagTraitUseRuleTest.php b/tests/PHPStan/Rules/Classes/MethodTagTraitUseRuleTest.php index 241f56e472..d2c390632a 100644 --- a/tests/PHPStan/Rules/Classes/MethodTagTraitUseRuleTest.php +++ b/tests/PHPStan/Rules/Classes/MethodTagTraitUseRuleTest.php @@ -10,7 +10,7 @@ use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule as TRule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -61,12 +61,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnum(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/method-tag-trait-enum.php'], [ [ 'PHPDoc tag @method for method MethodTagTraitEnum\Foo::doFoo() return type contains unknown class MethodTagTraitEnum\intt.', diff --git a/tests/PHPStan/Rules/Classes/MixinRuleTest.php b/tests/PHPStan/Rules/Classes/MixinRuleTest.php index 8a0e3a3e6a..7cbd36cda4 100644 --- a/tests/PHPStan/Rules/Classes/MixinRuleTest.php +++ b/tests/PHPStan/Rules/Classes/MixinRuleTest.php @@ -10,7 +10,7 @@ use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -115,12 +115,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/mixin-enums.php'], [ [ 'PHPDoc tag @mixin contains non-object type int.', diff --git a/tests/PHPStan/Rules/Classes/NonClassAttributeClassRuleTest.php b/tests/PHPStan/Rules/Classes/NonClassAttributeClassRuleTest.php index f3e2b90cae..1b7901e273 100644 --- a/tests/PHPStan/Rules/Classes/NonClassAttributeClassRuleTest.php +++ b/tests/PHPStan/Rules/Classes/NonClassAttributeClassRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -39,12 +39,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/enum-cannot-be-attribute.php'], [ [ 'Enum cannot be an Attribute class.', diff --git a/tests/PHPStan/Rules/Classes/RequireExtendsRuleTest.php b/tests/PHPStan/Rules/Classes/RequireExtendsRuleTest.php index 03f3361bef..966fac799a 100644 --- a/tests/PHPStan/Rules/Classes/RequireExtendsRuleTest.php +++ b/tests/PHPStan/Rules/Classes/RequireExtendsRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -17,12 +17,9 @@ protected function getRule(): Rule return new RequireExtendsRule(); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1'); - } - $expectedErrors = [ [ 'Trait IncompatibleRequireExtends\ValidTrait requires using class to extend IncompatibleRequireExtends\SomeClass, but IncompatibleRequireExtends\InValidTraitUse2 does not.', diff --git a/tests/PHPStan/Rules/Classes/RequireImplementsRuleTest.php b/tests/PHPStan/Rules/Classes/RequireImplementsRuleTest.php index 6a147e9398..41d2668a4b 100644 --- a/tests/PHPStan/Rules/Classes/RequireImplementsRuleTest.php +++ b/tests/PHPStan/Rules/Classes/RequireImplementsRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -17,12 +17,9 @@ protected function getRule(): Rule return new RequireImplementsRule(); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1'); - } - $expectedErrors = [ [ 'Trait IncompatibleRequireImplements\ValidTrait requires using class to implement IncompatibleRequireImplements\RequiredInterface, but IncompatibleRequireImplements\InValidTraitUse2 does not.', diff --git a/tests/PHPStan/Rules/Comparison/BooleanAndConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/BooleanAndConstantConditionRuleTest.php index 844d392d49..e8744f7f51 100644 --- a/tests/PHPStan/Rules/Comparison/BooleanAndConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/BooleanAndConstantConditionRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @extends RuleTestCase @@ -272,9 +273,7 @@ public static function dataTreatPhpDocTypesAsCertainRegression(): array ]; } - /** - * @dataProvider dataTreatPhpDocTypesAsCertainRegression - */ + #[DataProvider('dataTreatPhpDocTypesAsCertainRegression')] public function testTreatPhpDocTypesAsCertainRegression(bool $treatPhpDocTypesAsCertain): void { $this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain; @@ -357,9 +356,9 @@ public static function dataBug4969(): iterable } /** - * @dataProvider dataBug4969 * @param list $expectedErrors */ + #[DataProvider('dataBug4969')] public function testBug4969(bool $treatPhpDocTypesAsCertain, array $expectedErrors): void { $this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain; @@ -416,9 +415,9 @@ public static function dataReportAlwaysTrueInLastCondition(): iterable } /** - * @dataProvider dataReportAlwaysTrueInLastCondition * @param list $expectedErrors */ + #[DataProvider('dataReportAlwaysTrueInLastCondition')] public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void { $this->treatPhpDocTypesAsCertain = true; diff --git a/tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php index 58283f718d..24df1d9ea1 100644 --- a/tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @extends RuleTestCase @@ -113,9 +114,7 @@ public static function dataTreatPhpDocTypesAsCertainRegression(): array ]; } - /** - * @dataProvider dataTreatPhpDocTypesAsCertainRegression - */ + #[DataProvider('dataTreatPhpDocTypesAsCertainRegression')] public function testTreatPhpDocTypesAsCertainRegression(bool $treatPhpDocTypesAsCertain): void { $this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain; @@ -190,9 +189,9 @@ public static function dataReportAlwaysTrueInLastCondition(): iterable } /** - * @dataProvider dataReportAlwaysTrueInLastCondition * @param list $expectedErrors */ + #[DataProvider('dataReportAlwaysTrueInLastCondition')] public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void { $this->treatPhpDocTypesAsCertain = true; diff --git a/tests/PHPStan/Rules/Comparison/BooleanOrConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/BooleanOrConstantConditionRuleTest.php index d648ef93c9..a1a399005e 100644 --- a/tests/PHPStan/Rules/Comparison/BooleanOrConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/BooleanOrConstantConditionRuleTest.php @@ -4,7 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -255,21 +256,16 @@ public static function dataTreatPhpDocTypesAsCertainRegression(): array ]; } - /** - * @dataProvider dataTreatPhpDocTypesAsCertainRegression - */ + #[DataProvider('dataTreatPhpDocTypesAsCertainRegression')] public function testTreatPhpDocTypesAsCertainRegression(bool $treatPhpDocTypesAsCertain): void { $this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain; $this->analyse([__DIR__ . '/data/boolean-or-treat-phpdoc-types-regression.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug6258(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-6258.php'], []); } @@ -342,9 +338,9 @@ public static function dataReportAlwaysTrueInLastCondition(): iterable } /** - * @dataProvider dataReportAlwaysTrueInLastCondition * @param list $expectedErrors */ + #[DataProvider('dataReportAlwaysTrueInLastCondition')] public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void { $this->treatPhpDocTypesAsCertain = true; diff --git a/tests/PHPStan/Rules/Comparison/ConstantLooseComparisonRuleTest.php b/tests/PHPStan/Rules/Comparison/ConstantLooseComparisonRuleTest.php index 7e772a6153..e1a9a3db03 100644 --- a/tests/PHPStan/Rules/Comparison/ConstantLooseComparisonRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/ConstantLooseComparisonRuleTest.php @@ -4,6 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_merge; use const PHP_VERSION_ID; @@ -58,12 +60,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug8485(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-8485.php'], [ [ 'Loose comparison using == between Bug8485\E::c and Bug8485\E::c will always evaluate to true.', @@ -110,9 +109,9 @@ public static function dataReportAlwaysTrueInLastCondition(): iterable } /** - * @dataProvider dataReportAlwaysTrueInLastCondition * @param list $expectedErrors */ + #[DataProvider('dataReportAlwaysTrueInLastCondition')] public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void { $this->reportAlwaysTrueInLastCondition = $reportAlwaysTrueInLastCondition; @@ -132,9 +131,9 @@ public static function dataTreatPhpDocTypesAsCertain(): iterable } /** - * @dataProvider dataTreatPhpDocTypesAsCertain * @param list $expectedErrors */ + #[DataProvider('dataTreatPhpDocTypesAsCertain')] public function testTreatPhpDocTypesAsCertain(bool $treatPhpDocTypesAsCertain, array $expectedErrors): void { $this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain; diff --git a/tests/PHPStan/Rules/Comparison/ElseIfConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/ElseIfConstantConditionRuleTest.php index 1cdcd02893..9eec3deec1 100644 --- a/tests/PHPStan/Rules/Comparison/ElseIfConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/ElseIfConstantConditionRuleTest.php @@ -4,7 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -82,9 +83,9 @@ public static function dataRule(): iterable } /** - * @dataProvider dataRule * @param list $expectedErrors */ + #[DataProvider('dataRule')] public function testRule(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void { $this->treatPhpDocTypesAsCertain = true; @@ -121,12 +122,9 @@ public function testReportPhpDoc(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug11674(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-11674.php'], [ [ @@ -140,12 +138,9 @@ public function testBug11674(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug6947(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-6947.php'], [ [ diff --git a/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php index 4daa97d5dc..eee1500835 100644 --- a/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -131,12 +131,9 @@ public function testBug6902(): void $this->analyse([__DIR__ . '/data/bug-6902.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug8485(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->treatPhpDocTypesAsCertain = true; // reported by ConstantLooseComparisonRule instead diff --git a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php index 9ad101b290..2ffbddf715 100644 --- a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php @@ -4,12 +4,13 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use stdClass; use function array_filter; use function array_map; use function array_values; use function count; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -41,12 +42,9 @@ protected function shouldTreatPhpDocTypesAsCertain(): bool return $this->treatPhpDocTypesAsCertain; } + #[RequiresPhp('>= 8.0')] public function testImpossibleCheckTypeFunctionCall(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse( [__DIR__ . '/data/check-type-function-call.php'], @@ -360,12 +358,9 @@ public function testBug4999(): void $this->analyse([__DIR__ . '/data/bug-4999.php'], []); } + #[RequiresPhp('>= 8.1')] public function testArrayIsList(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/array-is-list.php'], [ [ @@ -497,12 +492,9 @@ public function testBug7079(): void $this->analyse([__DIR__ . '/data/bug-7079.php'], []); } + #[RequiresPhp('>= 8.0')] public function testConditionalTypesInference(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/../../Analyser/nsrt/conditional-types-inference.php'], [ [ @@ -534,12 +526,9 @@ public function testBug6697(): void $this->analyse([__DIR__ . '/data/bug-6697.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug6443(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-6443.php'], []); } @@ -696,9 +685,9 @@ public static function dataReportAlwaysTrueInLastCondition(): iterable } /** - * @dataProvider dataReportAlwaysTrueInLastCondition * @param list $expectedErrors */ + #[DataProvider('dataReportAlwaysTrueInLastCondition')] public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void { $this->treatPhpDocTypesAsCertain = true; @@ -878,12 +867,9 @@ private static function getLooseComparisonAgainsEnumsIssues(): array ]; } + #[RequiresPhp('>= 8.1')] public function testLooseComparisonAgainstEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->treatPhpDocTypesAsCertain = true; $issues = array_map( static function (array $i): array { @@ -904,12 +890,9 @@ public function testNonStrictInArray(): void $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-9662.php'], []); } + #[RequiresPhp('>= 8.1')] public function testNonStrictInArrayEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your %configurationFile%.'; $this->treatPhpDocTypesAsCertain = true; @@ -935,12 +918,9 @@ public function testNonStrictInArrayEnums(): void ]); } + #[RequiresPhp('>= 8.1')] public function testLooseComparisonAgainstEnumsNoPhpdoc(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->treatPhpDocTypesAsCertain = false; $issues = self::getLooseComparisonAgainsEnumsIssues(); $issues = array_values(array_filter($issues, static fn (array $i) => count($i) === 2)); @@ -977,12 +957,9 @@ public function testBug3979(): void $this->analyse([__DIR__ . '/data/bug-3979.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug8464(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-8464.php'], []); } diff --git a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeMethodCallRuleTest.php b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeMethodCallRuleTest.php index 843e7fee11..3fd625a4b1 100644 --- a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeMethodCallRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeMethodCallRuleTest.php @@ -4,7 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -199,12 +200,9 @@ public function testReportPhpDoc(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug8169(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-8169.php'], [ [ @@ -244,9 +242,9 @@ public static function dataReportAlwaysTrueInLastCondition(): iterable } /** - * @dataProvider dataReportAlwaysTrueInLastCondition * @param list $expectedErrors */ + #[DataProvider('dataReportAlwaysTrueInLastCondition')] public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void { $this->treatPhpDocTypesAsCertain = true; diff --git a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeStaticMethodCallRuleTest.php b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeStaticMethodCallRuleTest.php index 685ce36b67..1b43cdea9d 100644 --- a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeStaticMethodCallRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeStaticMethodCallRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @extends RuleTestCase @@ -134,9 +135,9 @@ public static function dataReportAlwaysTrueInLastCondition(): iterable } /** - * @dataProvider dataReportAlwaysTrueInLastCondition * @param list $expectedErrors */ + #[DataProvider('dataReportAlwaysTrueInLastCondition')] public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void { $this->treatPhpDocTypesAsCertain = true; diff --git a/tests/PHPStan/Rules/Comparison/MatchExpressionDoNotRememberPossiblyImpureValuesRuleTest.php b/tests/PHPStan/Rules/Comparison/MatchExpressionDoNotRememberPossiblyImpureValuesRuleTest.php index b52785c6f5..f81136f8d6 100644 --- a/tests/PHPStan/Rules/Comparison/MatchExpressionDoNotRememberPossiblyImpureValuesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/MatchExpressionDoNotRememberPossiblyImpureValuesRuleTest.php @@ -4,8 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_merge; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -18,21 +18,15 @@ protected function getRule(): Rule return self::getContainer()->getByType(MatchExpressionRule::class); } + #[RequiresPhp('>= 8.1')] public function testBug9357(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9357.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9007(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9007.php'], []); } diff --git a/tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php b/tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php index b5cb2d4407..5224ff9d42 100644 --- a/tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php @@ -4,7 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -112,20 +113,15 @@ public function testBug4857(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug5454(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } $this->analyse([__DIR__ . '/data/bug-5454.php'], []); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/match-enums.php'], [ [ 'Match expression does not handle remaining values: MatchEnums\Foo::THREE|MatchEnums\Foo::TWO', @@ -167,21 +163,15 @@ public function testEnums(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug6394(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-6394.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug6115(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-6115.php'], [ [ 'Match expression does not handle remaining value: 3', @@ -190,71 +180,54 @@ public function testBug6115(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug7095(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-7095.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug7176(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $this->analyse([__DIR__ . '/data/bug-7176.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug6064(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $this->analyse([__DIR__ . '/data/bug-6064.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug6647(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $this->analyse([__DIR__ . '/data/bug-6647.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug7622(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } $this->treatPhpDocTypesAsCertain = false; $this->analyse([__DIR__ . '/data/bug-7622.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug7698(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $this->treatPhpDocTypesAsCertain = false; $this->analyse([__DIR__ . '/data/bug-7698.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug7746(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-7746.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug8240(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-8240.php'], [ [ @@ -270,11 +243,9 @@ public function testBug8240(): void ]); } + #[RequiresPhp('>= 8.1')] public function testLastArmAlwaysTrue(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $this->treatPhpDocTypesAsCertain = true; $tipText = 'Remove remaining cases below this one and this error will disappear too.'; $this->analyse([__DIR__ . '/data/last-match-arm-always-true.php'], [ @@ -344,171 +315,118 @@ public static function dataReportAlwaysTrueInLastCondition(): iterable } /** - * @dataProvider dataReportAlwaysTrueInLastCondition * @param list $expectedErrors */ + #[RequiresPhp('>= 8.1')] + #[DataProvider('dataReportAlwaysTrueInLastCondition')] public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $this->treatPhpDocTypesAsCertain = true; $this->reportAlwaysTrueInLastCondition = $reportAlwaysTrueInLastCondition; $this->analyse([__DIR__ . '/data/match-always-true-last-arm.php'], $expectedErrors); } + #[RequiresPhp('>= 8.0')] public function testBug8932(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = false; $this->analyse([__DIR__ . '/data/bug-8932.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug8937(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = false; $this->analyse([__DIR__ . '/data/bug-8937.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug8900(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-8900.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug4451(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-4451.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9007(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9007.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9457(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9457.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug8614(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-8614.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug8536(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-8536.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9499(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9499.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug6407(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-6407.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBugUnhandledTrueWithComplexCondition(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-unhandled-true-with-complex-condition.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug11246(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-11246.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9879(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9879.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug11313(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-11313.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug9436(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-9436.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug11852(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-11852.php'], []); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/match-expr-property-hooks.php'], [ [ 'Match expression does not handle remaining value: 3', diff --git a/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php index 244aa3c660..e6913ff669 100644 --- a/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php @@ -4,7 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -105,11 +106,9 @@ public function testBug5295(): void $this->analyse([__DIR__ . '/data/bug-5295.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug7052(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $this->analyse([__DIR__ . '/data/bug-7052.php'], [ [ 'Comparison operation ">" between Bug7052\Foo::A and Bug7052\Foo::B is always false.', @@ -189,9 +188,9 @@ public static function dataTreatPhpDocTypesAsCertain(): iterable } /** - * @dataProvider dataTreatPhpDocTypesAsCertain * @param list $expectedErrors */ + #[DataProvider('dataTreatPhpDocTypesAsCertain')] public function testTreatPhpDocTypesAsCertain(bool $treatPhpDocTypesAsCertain, array $expectedErrors): void { $this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain; diff --git a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php index e694b94796..5e31f50619 100644 --- a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php @@ -5,6 +5,8 @@ use PHPStan\Analyser\RicherScopeGetTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_INT_SIZE; use const PHP_VERSION_ID; @@ -486,12 +488,9 @@ public function testBug8158(): void $this->analyse([__DIR__ . '/data/bug-8158.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug8485(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-8485.php'], [ [ 'Strict comparison using === between Bug8485\E::c and Bug8485\E::c will always evaluate to true.', @@ -542,12 +541,9 @@ public function testBug8586(): void $this->analyse([__DIR__ . '/data/bug-8586.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug4242(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-4242.php'], []); } @@ -643,12 +639,9 @@ public function testBug7578(): void $this->analyse([__DIR__ . '/data/bug-7578.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug6260(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = false; $this->analyse([__DIR__ . '/data/bug-6260.php'], []); } @@ -723,15 +716,12 @@ public static function dataLastMatchArm(): iterable } /** - * @dataProvider dataLastMatchArm * @param list $expectedErrors */ + #[RequiresPhp('>= 8.1')] + #[DataProvider('dataLastMatchArm')] public function testLastMatchArm(bool $reportAlwaysTrueInLastCondition, array $expectedErrors): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->reportAlwaysTrueInLastCondition = $reportAlwaysTrueInLastCondition; $this->analyse([__DIR__ . '/data/strict-comparison-last-match-arm.php'], $expectedErrors); } @@ -782,12 +772,9 @@ public function testBug9104(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnumTips(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/strict-comparison-enum-tips.php'], [ [ 'Strict comparison using === between StrictComparisonEnumTips\SomeEnum::Two and StrictComparisonEnumTips\SomeEnum::Two will always evaluate to true.', @@ -797,12 +784,9 @@ public function testEnumTips(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug9142(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9142.php'], [ [ 'Strict comparison using === between $this(Bug9142\MyEnum) and Bug9142\MyEnum::Three will always evaluate to false.', @@ -815,30 +799,21 @@ public function testBug9142(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug4061(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-4061.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9723(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9723.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9723b(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9723b.php'], []); } diff --git a/tests/PHPStan/Rules/Constants/FinalConstantRuleTest.php b/tests/PHPStan/Rules/Constants/FinalConstantRuleTest.php index 0e2938f22c..3f0430b2b4 100644 --- a/tests/PHPStan/Rules/Constants/FinalConstantRuleTest.php +++ b/tests/PHPStan/Rules/Constants/FinalConstantRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @extends RuleTestCase @@ -39,9 +40,9 @@ public static function dataRule(): array } /** - * @dataProvider dataRule * @param list $errors */ + #[DataProvider('dataRule')] public function testRule(int $phpVersionId, array $errors): void { $this->phpVersionId = $phpVersionId; diff --git a/tests/PHPStan/Rules/Constants/MissingClassConstantTypehintRuleTest.php b/tests/PHPStan/Rules/Constants/MissingClassConstantTypehintRuleTest.php index 13e745a3d1..2c95dbb317 100644 --- a/tests/PHPStan/Rules/Constants/MissingClassConstantTypehintRuleTest.php +++ b/tests/PHPStan/Rules/Constants/MissingClassConstantTypehintRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\MissingTypehintCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -37,20 +37,15 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.2')] public function testBug8957(): void { - if (PHP_VERSION_ID < 80200) { - $this->markTestSkipped('This test needs PHP 8.2'); - } $this->analyse([__DIR__ . '/data/bug-8957.php'], []); } + #[RequiresPhp('>= 8.3')] public function testRuleShouldNotApplyToNativeTypes(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('This test needs PHP 8.3'); - } - $this->analyse([__DIR__ . '/data/class-constant-native-type.php'], [ [ 'Constant ClassConstantNativeTypeForMissingTypehintRule\Foo::B type has no value type specified in iterable type array.', diff --git a/tests/PHPStan/Rules/Constants/OverridingConstantRuleTest.php b/tests/PHPStan/Rules/Constants/OverridingConstantRuleTest.php index 6ce51b0297..5e14d98461 100644 --- a/tests/PHPStan/Rules/Constants/OverridingConstantRuleTest.php +++ b/tests/PHPStan/Rules/Constants/OverridingConstantRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @extends RuleTestCase */ @@ -90,12 +91,9 @@ public function testFinal(): void $this->analyse([__DIR__ . '/data/overriding-final-constant.php'], $errors); } + #[RequiresPhp('>= 8.3')] public function testNativeTypes(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->analyse([__DIR__ . '/data/overriding-constant-native-types.php'], [ [ 'Native type int|string of constant OverridingConstantNativeTypes\Bar::D is not covariant with native type int of constant OverridingConstantNativeTypes\Foo::D.', diff --git a/tests/PHPStan/Rules/Constants/ValueAssignedToClassConstantRuleTest.php b/tests/PHPStan/Rules/Constants/ValueAssignedToClassConstantRuleTest.php index 7942506ca1..5405390a90 100644 --- a/tests/PHPStan/Rules/Constants/ValueAssignedToClassConstantRuleTest.php +++ b/tests/PHPStan/Rules/Constants/ValueAssignedToClassConstantRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule as TRule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -60,12 +60,9 @@ public function testBug5655(): void $this->analyse([__DIR__ . '/data/bug-5655.php'], []); } + #[RequiresPhp('>= 8.3')] public function testNativeType(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->analyse([__DIR__ . '/data/value-assigned-to-class-constant-native-type.php'], [ [ 'Constant ValueAssignedToClassConstantNativeType\Foo::BAR (int) does not accept value \'bar\'.', @@ -86,12 +83,9 @@ public function testNativeType(): void ]); } + #[RequiresPhp('>= 8.3')] public function testBug10212(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->analyse([__DIR__ . '/data/bug-10212.php'], [ [ 'Constant Bug10212\HelloWorld::B (Bug10212\X\Foo) does not accept value Bug10212\Foo::Bar.', diff --git a/tests/PHPStan/Rules/DeadCode/CallToMethodStatementWithoutImpurePointsRuleTest.php b/tests/PHPStan/Rules/DeadCode/CallToMethodStatementWithoutImpurePointsRuleTest.php index 923c2b7883..e0bd3d2168 100644 --- a/tests/PHPStan/Rules/DeadCode/CallToMethodStatementWithoutImpurePointsRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/CallToMethodStatementWithoutImpurePointsRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -75,11 +75,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug11011(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } $this->analyse([__DIR__ . '/data/bug-11011.php'], [ [ 'Call to method Bug11011\AnotherPureImpl::doFoo() on a separate line has no effect.', @@ -88,11 +86,9 @@ public function testBug11011(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug12379(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $this->analyse([__DIR__ . '/data/bug-12379.php'], []); } diff --git a/tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php b/tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php index d852f08d8d..87e0dd0c11 100644 --- a/tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @extends RuleTestCase @@ -81,9 +82,7 @@ public static function dataBugWithoutGitHubIssue1(): array ]; } - /** - * @dataProvider dataBugWithoutGitHubIssue1 - */ + #[DataProvider('dataBugWithoutGitHubIssue1')] public function testBugWithoutGitHubIssue1(bool $treatPhpDocTypesAsCertain): void { $this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain; diff --git a/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php b/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php index 9ef9924063..79e15a843c 100644 --- a/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php @@ -7,8 +7,8 @@ use PHPStan\Rules\Constants\DirectAlwaysUsedClassConstantsExtensionProvider; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use UnusedPrivateConstant\TestExtension; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -54,12 +54,9 @@ public function testBug5651(): void $this->analyse([__DIR__ . '/data/bug-5651.php'], []); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/unused-private-constant-enum.php'], [ [ 'Constant UnusedPrivateConstantEnum\Foo::TEST_2 is unused.', @@ -74,21 +71,15 @@ public function testBug6758(): void $this->analyse([__DIR__ . '/data/bug-6758.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug8204(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-8204.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9005(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9005.php'], []); } @@ -97,12 +88,9 @@ public function testBug9765(): void $this->analyse([__DIR__ . '/data/bug-9765.php'], []); } + #[RequiresPhp('>= 8.3')] public function testDynamicConstantFetch(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->analyse([__DIR__ . '/data/unused-private-constant-dynamic-fetch.php'], [ [ 'Constant UnusedPrivateConstantDynamicFetch\Baz::FOO is unused.', diff --git a/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php b/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php index ca57318a59..093d372358 100644 --- a/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\Methods\DirectAlwaysUsedMethodExtensionProvider; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -72,21 +72,15 @@ public function testNullsafe(): void $this->analyse([__DIR__ . '/data/nullsafe-unused-private-method.php'], []); } + #[RequiresPhp('>= 8.1')] public function testFirstClassCallable(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/callable-unused-private-method.php'], []); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/unused-private-method-enum.php'], [ [ 'Method UnusedPrivateMethodEnunm\Foo::doBaz() is unused.', @@ -114,12 +108,9 @@ public function testBug8346(): void $this->analyse([__DIR__ . '/data/bug-8346.php'], []); } + #[RequiresPhp('>= 8.1')] public function testFalsePositiveWithTraitUse(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/unused-method-false-positive-with-trait.php'], []); } diff --git a/tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php b/tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php index c83a84d425..3b909661e8 100644 --- a/tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php @@ -7,8 +7,8 @@ use PHPStan\Rules\Properties\ReadWritePropertiesExtension; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function in_array; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -257,12 +257,9 @@ public function testBug6107(): void $this->analyse([__DIR__ . '/data/bug-6107.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug8204(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->alwaysWrittenTags = []; $this->alwaysReadTags = []; $this->analyse([__DIR__ . '/data/bug-8204.php'], []); @@ -289,23 +286,17 @@ public function testBug9765(): void $this->analyse([__DIR__ . '/data/bug-9765.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug10059(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->alwaysWrittenTags = []; $this->alwaysReadTags = []; $this->analyse([__DIR__ . '/data/bug-10059.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug10628(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->alwaysWrittenTags = []; $this->alwaysReadTags = []; $this->analyse([__DIR__ . '/data/bug-10628.php'], []); @@ -347,12 +338,9 @@ public function testBug11802(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $tip = 'See: https://phpstan.org/developing-extensions/always-read-written-properties'; $this->alwaysWrittenTags = []; @@ -387,24 +375,18 @@ public function testPropertyHooks(): void ]); } + #[RequiresPhp('>= 8.4')] public function testBug12621(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->alwaysWrittenTags = []; $this->alwaysReadTags = []; $this->analyse([__DIR__ . '/data/bug-12621.php'], []); } + #[RequiresPhp('>= 8.4')] public function testBug12702(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->alwaysWrittenTags = []; $this->alwaysReadTags = []; diff --git a/tests/PHPStan/Rules/EnumCases/EnumCaseAttributesRuleTest.php b/tests/PHPStan/Rules/EnumCases/EnumCaseAttributesRuleTest.php index f789f9c092..1028c66778 100644 --- a/tests/PHPStan/Rules/EnumCases/EnumCaseAttributesRuleTest.php +++ b/tests/PHPStan/Rules/EnumCases/EnumCaseAttributesRuleTest.php @@ -13,7 +13,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -48,12 +48,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/enum-case-attributes.php'], [ [ 'Attribute class EnumCaseAttributes\AttributeWithPropertyTarget does not have the class constant target.', diff --git a/tests/PHPStan/Rules/Exceptions/AbilityToDisableImplicitThrowsTest.php b/tests/PHPStan/Rules/Exceptions/AbilityToDisableImplicitThrowsTest.php index c0db350002..8dd7f30a05 100644 --- a/tests/PHPStan/Rules/Exceptions/AbilityToDisableImplicitThrowsTest.php +++ b/tests/PHPStan/Rules/Exceptions/AbilityToDisableImplicitThrowsTest.php @@ -4,8 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_merge; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -34,12 +34,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/unthrown-exception-property-hooks-implicit-throws-disabled.php'], [ [ 'Dead catch - UnthrownExceptionPropertyHooksImplicitThrowsDisabled\MyCustomException is never thrown in the try block.', diff --git a/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php b/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php index f29b8cbc02..272c010d97 100644 --- a/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php @@ -6,7 +6,7 @@ use InvalidArgumentException; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -299,12 +299,9 @@ public function testBug4863(): void $this->analyse([__DIR__ . '/data/bug-4863.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug5866(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/bug-5866.php'], []); } @@ -390,12 +387,9 @@ public function testBug5903(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug6115(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-6115.php'], [ [ 'Dead catch - UnhandledMatchError is never thrown in the try block.', @@ -466,12 +460,9 @@ public function testBug6786(): void $this->analyse([__DIR__ . '/data/bug-6786.php'], []); } + #[RequiresPhp('>= 8.0')] public function testUnionTypeError(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/union-type-error.php'], [ [ 'Dead catch - TypeError is never thrown in the try block.', @@ -607,21 +598,15 @@ public function testBug5650(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug9568(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-9568.php'], []); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - self::markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/unthrown-exception-property-hooks.php'], [ [ 'Dead catch - UnthrownExceptionPropertyHooks\MyCustomException is never thrown in the try block.', diff --git a/tests/PHPStan/Rules/Exceptions/DefaultExceptionTypeResolverTest.php b/tests/PHPStan/Rules/Exceptions/DefaultExceptionTypeResolverTest.php index 22f47f3615..1ca947f5d6 100644 --- a/tests/PHPStan/Rules/Exceptions/DefaultExceptionTypeResolverTest.php +++ b/tests/PHPStan/Rules/Exceptions/DefaultExceptionTypeResolverTest.php @@ -8,6 +8,7 @@ use PHPStan\Analyser\ScopeContext; use PHPStan\Analyser\ScopeFactory; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class DefaultExceptionTypeResolverTest extends PHPStanTestCase { @@ -127,12 +128,12 @@ public static function dataIsCheckedException(): array } /** - * @dataProvider dataIsCheckedException * @param string[] $uncheckedExceptionRegexes * @param string[] $uncheckedExceptionClasses * @param string[] $checkedExceptionRegexes * @param string[] $checkedExceptionClasses */ + #[DataProvider('dataIsCheckedException')] public function testIsCheckedException( array $uncheckedExceptionRegexes, array $uncheckedExceptionClasses, diff --git a/tests/PHPStan/Rules/Exceptions/MissingCheckedExceptionInPropertyHookThrowsRuleTest.php b/tests/PHPStan/Rules/Exceptions/MissingCheckedExceptionInPropertyHookThrowsRuleTest.php index 10af4b427f..4d46df5def 100644 --- a/tests/PHPStan/Rules/Exceptions/MissingCheckedExceptionInPropertyHookThrowsRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/MissingCheckedExceptionInPropertyHookThrowsRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -26,12 +26,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.4')] public function testRule(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/missing-exception-property-hook-throws.php'], [ [ 'Get hook for property MissingExceptionPropertyHookThrows\Foo::$k throws checked exception InvalidArgumentException but it\'s missing from the PHPDoc @throws tag.', diff --git a/tests/PHPStan/Rules/Exceptions/NoncapturingCatchRuleTest.php b/tests/PHPStan/Rules/Exceptions/NoncapturingCatchRuleTest.php index 669adcc172..55cf2f2628 100644 --- a/tests/PHPStan/Rules/Exceptions/NoncapturingCatchRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/NoncapturingCatchRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use const PHP_VERSION_ID; /** @@ -42,10 +43,9 @@ public static function dataRule(): array } /** - * @dataProvider dataRule - * * @param list $expectedErrors */ + #[DataProvider('dataRule')] public function testRule(int $phpVersion, array $expectedErrors): void { $testVersion = new PhpVersion($phpVersion); diff --git a/tests/PHPStan/Rules/Exceptions/ThrowExprTypeRuleTest.php b/tests/PHPStan/Rules/Exceptions/ThrowExprTypeRuleTest.php index 102409e5a2..a415096826 100644 --- a/tests/PHPStan/Rules/Exceptions/ThrowExprTypeRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/ThrowExprTypeRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -57,12 +57,9 @@ public function testClassExists(): void $this->analyse([__DIR__ . '/data/throw-class-exists.php'], []); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/throw-values-nullsafe.php'], [ [ 'Invalid type Exception|null to throw.', diff --git a/tests/PHPStan/Rules/Exceptions/ThrowExpressionRuleTest.php b/tests/PHPStan/Rules/Exceptions/ThrowExpressionRuleTest.php index a45238c3e6..f7143269c3 100644 --- a/tests/PHPStan/Rules/Exceptions/ThrowExpressionRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/ThrowExpressionRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @extends RuleTestCase @@ -39,9 +40,9 @@ public static function dataRule(): array } /** - * @dataProvider dataRule * @param list $expectedErrors */ + #[DataProvider('dataRule')] public function testRule(int $phpVersion, array $expectedErrors): void { $this->phpVersion = new PhpVersion($phpVersion); diff --git a/tests/PHPStan/Rules/Exceptions/ThrowsVoidFunctionWithExplicitThrowPointRuleTest.php b/tests/PHPStan/Rules/Exceptions/ThrowsVoidFunctionWithExplicitThrowPointRuleTest.php index e2ae6dcac2..af4f7bc372 100644 --- a/tests/PHPStan/Rules/Exceptions/ThrowsVoidFunctionWithExplicitThrowPointRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/ThrowsVoidFunctionWithExplicitThrowPointRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use ThrowsVoidFunction\MyException; /** @@ -85,10 +86,10 @@ public static function dataRule(): array } /** - * @dataProvider dataRule * @param string[] $checkedExceptionClasses * @param list $errors */ + #[DataProvider('dataRule')] public function testRule(bool $missingCheckedExceptionInThrows, array $checkedExceptionClasses, array $errors): void { $this->missingCheckedExceptionInThrows = $missingCheckedExceptionInThrows; diff --git a/tests/PHPStan/Rules/Exceptions/ThrowsVoidMethodWithExplicitThrowPointRuleTest.php b/tests/PHPStan/Rules/Exceptions/ThrowsVoidMethodWithExplicitThrowPointRuleTest.php index 005b087f2c..196d99a84c 100644 --- a/tests/PHPStan/Rules/Exceptions/ThrowsVoidMethodWithExplicitThrowPointRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/ThrowsVoidMethodWithExplicitThrowPointRuleTest.php @@ -4,9 +4,10 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use ThrowsVoidMethod\MyException; use UnhandledMatchError; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -87,10 +88,10 @@ public static function dataRule(): array } /** - * @dataProvider dataRule * @param string[] $checkedExceptionClasses * @param list $errors */ + #[DataProvider('dataRule')] public function testRule(bool $missingCheckedExceptionInThrows, array $checkedExceptionClasses, array $errors): void { $this->missingCheckedExceptionInThrows = $missingCheckedExceptionInThrows; @@ -98,11 +99,9 @@ public function testRule(bool $missingCheckedExceptionInThrows, array $checkedEx $this->analyse([__DIR__ . '/data/throws-void-method.php'], $errors); } + #[RequiresPhp('>= 8.0')] public function testBug6910(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } $this->missingCheckedExceptionInThrows = false; $this->checkedExceptionClasses = [UnhandledMatchError::class]; $this->analyse([__DIR__ . '/data/bug-6910.php'], []); diff --git a/tests/PHPStan/Rules/Exceptions/ThrowsVoidPropertyHookWithExplicitThrowPointRuleTest.php b/tests/PHPStan/Rules/Exceptions/ThrowsVoidPropertyHookWithExplicitThrowPointRuleTest.php index 86fc804bfe..e7db139575 100644 --- a/tests/PHPStan/Rules/Exceptions/ThrowsVoidPropertyHookWithExplicitThrowPointRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/ThrowsVoidPropertyHookWithExplicitThrowPointRuleTest.php @@ -4,7 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -101,16 +102,13 @@ public static function dataRule(): array } /** - * @dataProvider dataRule * @param string[] $checkedExceptionClasses * @param list $errors */ + #[RequiresPhp('>= 8.4')] + #[DataProvider('dataRule')] public function testRule(bool $missingCheckedExceptionInThrows, array $checkedExceptionClasses, array $errors): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->missingCheckedExceptionInThrows = $missingCheckedExceptionInThrows; $this->checkedExceptionClasses = $checkedExceptionClasses; $this->analyse([__DIR__ . '/data/throws-void-property-hook.php'], $errors); diff --git a/tests/PHPStan/Rules/Exceptions/TooWideMethodThrowTypeRuleTest.php b/tests/PHPStan/Rules/Exceptions/TooWideMethodThrowTypeRuleTest.php index c3f2887c98..85cff48d9b 100644 --- a/tests/PHPStan/Rules/Exceptions/TooWideMethodThrowTypeRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/TooWideMethodThrowTypeRuleTest.php @@ -5,7 +5,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; use PHPStan\Type\FileTypeMapper; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -69,12 +70,9 @@ public function testImmediatelyCalledArrowFunction(): void ]); } + #[RequiresPhp('>= 8.1')] public function testFirstClassCallable(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/immediately-called-fcc.php'], []); } @@ -96,9 +94,9 @@ public static function dataRuleLookOnlyForExplicitThrowPoints(): iterable } /** - * @dataProvider dataRuleLookOnlyForExplicitThrowPoints * @param list $errors */ + #[DataProvider('dataRuleLookOnlyForExplicitThrowPoints')] public function testRuleLookOnlyForExplicitThrowPoints(bool $implicitThrows, array $errors): void { $this->implicitThrows = $implicitThrows; diff --git a/tests/PHPStan/Rules/Exceptions/TooWidePropertyHookThrowTypeRuleTest.php b/tests/PHPStan/Rules/Exceptions/TooWidePropertyHookThrowTypeRuleTest.php index a74effd6e0..da40cc6d80 100644 --- a/tests/PHPStan/Rules/Exceptions/TooWidePropertyHookThrowTypeRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/TooWidePropertyHookThrowTypeRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; use PHPStan\Type\FileTypeMapper; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -20,12 +20,9 @@ protected function getRule(): Rule return new TooWidePropertyHookThrowTypeRule(self::getContainer()->getByType(FileTypeMapper::class), new TooWideThrowTypeCheck($this->implicitThrows)); } + #[RequiresPhp('>= 8.4')] public function testRule(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/too-wide-throws-property-hook.php'], [ [ 'Get hook for property TooWideThrowsPropertyHook\Foo::$c has InvalidArgumentException in PHPDoc @throws tag but it\'s not thrown.', diff --git a/tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php b/tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php index 3415bfa8dd..99d577361e 100644 --- a/tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php @@ -6,7 +6,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -43,12 +43,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testRuleNever(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/arrow-function-never-return.php'], [ [ 'Anonymous function should never return but return statement found.', @@ -62,12 +59,9 @@ public function testBug3261(): void $this->analyse([__DIR__ . '/data/bug-3261.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug8179(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-8179.php'], []); } diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index f62a03d4ea..837f9faf73 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -9,6 +9,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -158,12 +160,9 @@ public function testRule(): void $this->analyse([__DIR__ . '/data/callables.php'], $errors); } + #[RequiresPhp('>= 8.0')] public function testNamedArguments(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/callables-named-arguments.php'], [ [ 'Missing parameter $j (int) in call to closure.', @@ -208,21 +207,18 @@ public static function dataBug3566(): array } /** - * @dataProvider dataBug3566 * @param list $errors */ + #[DataProvider('dataBug3566')] public function testBug3566(bool $checkExplicitMixed, array $errors): void { $this->checkExplicitMixed = $checkExplicitMixed; $this->analyse([__DIR__ . '/data/bug-3566.php'], $errors); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = true; $this->analyse([__DIR__ . '/data/callables-nullsafe.php'], [ [ diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 1c726b0ea3..9e95a0bcc8 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -9,6 +9,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function sprintf; use const PHP_VERSION_ID; @@ -421,12 +423,9 @@ public function testFputCsv(): void ]); } + #[RequiresPhp('>= 8.0')] public function testPutCsvWithStringable(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test skipped on lower version than 8.0 (needs Stringable interface, added in PHP8)'); - } - $this->analyse([__DIR__ . '/data/fputcsv-fields-parameter-php8.php'], [ // No issues expected ]); @@ -474,12 +473,9 @@ public function testGenericFunction(): void ]); } + #[RequiresPhp('>= 8.0')] public function testNamedArguments(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $errors = [ [ 'Missing parameter $j (int) in call to function FunctionNamedArguments\foo.', @@ -499,12 +495,9 @@ public function testNamedArguments(): void $this->analyse([__DIR__ . '/data/named-arguments.php'], $errors); } + #[RequiresPhp('>= 8.1')] public function testNamedArgumentsAfterUnpacking(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/named-arguments-after-unpacking.php'], [ [ 'Argument for parameter $b has already been passed.', @@ -555,12 +548,9 @@ public function testBug3920(): void $this->analyse([__DIR__ . '/data/bug-3920.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBugNumberFormatNamedArguments(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/number-format-named-arguments.php'], []); } @@ -805,12 +795,9 @@ public function testBug3660(): void ]); } + #[RequiresPhp('>= 8.0')] public function testExplode(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/explode-80.php'], [ [ 'Parameter #1 $separator of function explode expects non-empty-string, string given.', @@ -852,9 +839,7 @@ public static function dataArrayMapMultiple(): array ]; } - /** - * @dataProvider dataArrayMapMultiple - */ + #[DataProvider('dataArrayMapMultiple')] public function testArrayMapMultiple(bool $checkExplicitMixed): void { $this->checkExplicitMixed = $checkExplicitMixed; @@ -874,9 +859,7 @@ public static function dataArrayFilterCallback(): array ]; } - /** - * @dataProvider dataArrayFilterCallback - */ + #[DataProvider('dataArrayFilterCallback')] public function testArrayFilterCallback(bool $checkExplicitMixed): void { $this->checkExplicitMixed = $checkExplicitMixed; @@ -896,12 +879,9 @@ public function testArrayFilterCallback(bool $checkExplicitMixed): void $this->analyse([__DIR__ . '/data/array_filter_callback.php'], $errors); } + #[RequiresPhp('>= 8.4')] public function testArrayAllCallback(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test skipped on lower version than 8.4 (needs array_all function)'); - } - $this->analyse([__DIR__ . '/data/array_all.php'], [ [ 'Parameter #2 $callback of function array_all expects callable(1|2, \'bar\'|\'foo\'): bool, Closure(string, int): bool given.', @@ -926,12 +906,9 @@ public function testArrayAllCallback(): void ]); } + #[RequiresPhp('>= 8.4')] public function testArrayAnyCallback(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test skipped on lower version than 8.4 (needs array_any function)'); - } - $this->analyse([__DIR__ . '/data/array_any.php'], [ [ 'Parameter #2 $callback of function array_any expects callable(1|2, \'bar\'|\'foo\'): bool, Closure(string, int): bool given.', @@ -1236,12 +1213,9 @@ public function testDiscussion7450WithCheckExplicitMixed(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug7211(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1'); - } - $this->checkExplicitMixed = true; $this->analyse([__DIR__ . '/data/bug-7211.php'], []); } @@ -1272,11 +1246,9 @@ public function testBug7676(): void $this->analyse([__DIR__ . '/data/bug-7676.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug7138(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1'); - } $this->analyse([__DIR__ . '/data/bug-7138.php'], []); } @@ -1479,12 +1451,9 @@ public function testFilterInputType(): void $this->analyse([__DIR__ . '/data/filter-input-type.php'], $errors); } + #[RequiresPhp('>= 8.0')] public function testBug9283(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/bug-9283.php'], []); } @@ -1529,12 +1498,9 @@ public function testFlockParams(): void ]); } + #[RequiresPhp('>= 8.3')] public function testJsonValidate(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3'); - } - $this->analyse([__DIR__ . '/data/json_validate.php'], [ [ 'Parameter #2 $depth of function json_validate expects int<1, max>, 0 given.', @@ -1557,21 +1523,15 @@ public function testBug2508(): void $this->analyse([__DIR__ . '/data/bug-2508.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug6175(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-6175.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9699(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/bug-9699.php'], [ [ 'Parameter #1 $f of function Bug9699\int_int_int_string expects Closure(int, int, int, string): int, Closure(int, int, int ...): int given.', @@ -1595,12 +1555,9 @@ public function testBug9803(): void $this->analyse([__DIR__ . '/data/bug-9803.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug9018(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/bug-9018.php'], [ [ 'Unknown parameter $str1 in call to function levenshtein.', @@ -1621,48 +1578,33 @@ public function testBug9018(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug9399(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/bug-9399.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug9559(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/bug-9559.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug9923(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/bug-9923.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug9823(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/bug-9823.php'], []); } + #[RequiresPhp('>= 8.0')] public function testNamedParametersForMultiVariantFunctions(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/call-to-function-named-params-multivariant.php'], []); } @@ -1703,21 +1645,15 @@ public function testBug9793(): void $this->analyse([__DIR__ . '/data/bug-9793.php'], $errors); } + #[RequiresPhp('>= 8.0')] public function testCallToArrayFilterWithNullCallback(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/array_filter_null_callback.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug10171(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/bug-10171.php'], [ [ 'Unknown parameter $samesite in call to function setcookie.', @@ -1753,12 +1689,9 @@ public function testBug9580(): void $this->analyse([__DIR__ . '/data/bug-9580.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug7283(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-7283.php'], []); } @@ -1824,21 +1757,15 @@ public function testParamClosureThis(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug10297(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-10297.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug10974(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-10974.php'], []); } @@ -2029,12 +1956,9 @@ public function testBug7707(): void $this->analyse([__DIR__ . '/data/bug-7707.php'], []); } + #[RequiresPhp('>= 8.0')] public function testNoNamedArguments(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/no-named-arguments.php'], [ [ 'Function NoNamedArgumentsFunction\\foo invoked with named argument $i, but it\'s not allowed because of @no-named-arguments.', @@ -2090,12 +2014,9 @@ public function testBug11559b(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug9224(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9224.php'], []); } @@ -2122,39 +2043,27 @@ public function testBug12051(): void $this->analyse([__DIR__ . '/data/bug-12051.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug8046(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-8046.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug11942(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-11942.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug11418(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-11418.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9167(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9167.php'], []); } @@ -2211,12 +2120,9 @@ public function testBug7522(): void $this->analyse([__DIR__ . '/data/bug-7522.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug12847(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = true; $this->checkImplicitMixed = true; diff --git a/tests/PHPStan/Rules/Functions/CallToNonExistentFunctionRuleTest.php b/tests/PHPStan/Rules/Functions/CallToNonExistentFunctionRuleTest.php index bd5d50733e..00932fa18f 100644 --- a/tests/PHPStan/Rules/Functions/CallToNonExistentFunctionRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToNonExistentFunctionRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -100,12 +100,9 @@ public function testMatchExprAnalysis(): void ]); } + #[RequiresPhp('>= 8.0')] public function testCallToRemovedFunctionsOnPhp8(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/removed-functions-from-php8.php'], [ [ 'Function convert_cyr_string not found.', @@ -155,12 +152,9 @@ public function testCallToRemovedFunctionsOnPhp8(): void ]); } + #[RequiresPhp('>= 8.0')] public function testCreateFunctionPhp8(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/create_function.php'], [ [ 'Function create_function not found.', @@ -170,12 +164,9 @@ public function testCreateFunctionPhp8(): void ]); } + #[RequiresPhp('< 8.0')] public function testCreateFunctionPhp7(): void { - if (PHP_VERSION_ID >= 80000) { - $this->markTestSkipped('Test requires PHP 7.x.'); - } - $this->analyse([__DIR__ . '/data/create_function.php'], []); } @@ -220,21 +211,15 @@ public function testBug7952(): void $this->analyse([__DIR__ . '/data/bug-7952.php'], []); } + #[RequiresPhp('>= 8.2')] public function testBug8058(): void { - if (PHP_VERSION_ID < 80200) { - $this->markTestSkipped('Test requires PHP 8.2'); - } - $this->analyse([__DIR__ . '/../Methods/data/bug-8058.php'], []); } + #[RequiresPhp('< 8.2')] public function testBug8058b(): void { - if (PHP_VERSION_ID >= 80200) { - $this->markTestSkipped('Test requires PHP before 8.2'); - } - $this->analyse([__DIR__ . '/../Methods/data/bug-8058.php'], [ [ 'Function mysqli_execute_query not found.', diff --git a/tests/PHPStan/Rules/Functions/CallUserFuncRuleTest.php b/tests/PHPStan/Rules/Functions/CallUserFuncRuleTest.php index 25be7474e2..ba44a5bc0f 100644 --- a/tests/PHPStan/Rules/Functions/CallUserFuncRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallUserFuncRuleTest.php @@ -9,7 +9,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -23,12 +23,9 @@ protected function getRule(): Rule return new CallUserFuncRule($reflectionProvider, new FunctionCallParametersCheck(new RuleLevelHelper($reflectionProvider, true, false, true, true, false, false, true), new NullsafeCheck(), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), true, true, true, true)); } + #[RequiresPhp('>= 8.0')] public function testRule(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/call-user-func.php'], [ [ 'Callable passed to call_user_func() invoked with 0 parameters, 1 required.', @@ -82,12 +79,9 @@ public function testBug7057(): void $this->analyse([__DIR__ . '/data/bug-7057.php'], []); } + #[RequiresPhp('>= 8.1')] public function testNoNamedArguments(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/no-named-arguments-call-user-func.php'], [ [ 'Callable passed to call_user_func() invoked with named argument $i, but it\'s not allowed because of @no-named-arguments.', diff --git a/tests/PHPStan/Rules/Functions/ExistingClassesInArrowFunctionTypehintsRuleTest.php b/tests/PHPStan/Rules/Functions/ExistingClassesInArrowFunctionTypehintsRuleTest.php index 86a0b46f4f..b7d14e5ee6 100644 --- a/tests/PHPStan/Rules/Functions/ExistingClassesInArrowFunctionTypehintsRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ExistingClassesInArrowFunctionTypehintsRuleTest.php @@ -10,6 +10,8 @@ use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -79,9 +81,9 @@ public static function dataNativeUnionTypes(): array } /** - * @dataProvider dataNativeUnionTypes * @param list $errors */ + #[DataProvider('dataNativeUnionTypes')] public function testNativeUnionTypes(int $phpVersionId, array $errors): void { $this->phpVersionId = $phpVersionId; @@ -239,15 +241,12 @@ public static function dataRequiredParameterAfterOptional(): array } /** - * @dataProvider dataRequiredParameterAfterOptional * @param list $errors */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataRequiredParameterAfterOptional')] public function testRequiredParameterAfterOptional(int $phpVersionId, array $errors): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->phpVersionId = $phpVersionId; $this->analyse([__DIR__ . '/data/required-parameter-after-optional-arrow.php'], $errors); } @@ -281,9 +280,9 @@ public static function dataIntersectionTypes(): array } /** - * @dataProvider dataIntersectionTypes * @param list $errors */ + #[DataProvider('dataIntersectionTypes')] public function testIntersectionTypes(int $phpVersion, array $errors): void { $this->phpVersionId = $phpVersion; diff --git a/tests/PHPStan/Rules/Functions/ExistingClassesInClosureTypehintsRuleTest.php b/tests/PHPStan/Rules/Functions/ExistingClassesInClosureTypehintsRuleTest.php index f5318f9002..b01e0f5230 100644 --- a/tests/PHPStan/Rules/Functions/ExistingClassesInClosureTypehintsRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ExistingClassesInClosureTypehintsRuleTest.php @@ -10,6 +10,8 @@ use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -123,9 +125,9 @@ public static function dataNativeUnionTypes(): array } /** - * @dataProvider dataNativeUnionTypes * @param list $errors */ + #[DataProvider('dataNativeUnionTypes')] public function testNativeUnionTypes(int $phpVersionId, array $errors): void { $this->phpVersionId = $phpVersionId; @@ -283,15 +285,12 @@ public static function dataRequiredParameterAfterOptional(): array } /** - * @dataProvider dataRequiredParameterAfterOptional * @param list $errors */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataRequiredParameterAfterOptional')] public function testRequiredParameterAfterOptional(int $phpVersionId, array $errors): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->phpVersionId = $phpVersionId; $this->analyse([__DIR__ . '/data/required-parameter-after-optional-closures.php'], $errors); } @@ -325,9 +324,9 @@ public static function dataIntersectionTypes(): array } /** - * @dataProvider dataIntersectionTypes * @param list $errors */ + #[DataProvider('dataIntersectionTypes')] public function testIntersectionTypes(int $phpVersion, array $errors): void { $this->phpVersionId = $phpVersion; @@ -335,12 +334,9 @@ public function testIntersectionTypes(int $phpVersion, array $errors): void $this->analyse([__DIR__ . '/data/closure-intersection-types.php'], $errors); } + #[RequiresPhp('>= 8.4')] public function testDeprecatedImplicitlyNullableParameterType(): void { - if (PHP_VERSION_ID < 80400) { - self::markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/closure-implicitly-nullable.php'], [ [ 'Deprecated in PHP 8.4: Parameter #3 $c (int) is implicitly nullable via default value null.', diff --git a/tests/PHPStan/Rules/Functions/ExistingClassesInTypehintsRuleTest.php b/tests/PHPStan/Rules/Functions/ExistingClassesInTypehintsRuleTest.php index 6d63bbfd65..e9ec0e10b9 100644 --- a/tests/PHPStan/Rules/Functions/ExistingClassesInTypehintsRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ExistingClassesInTypehintsRuleTest.php @@ -10,6 +10,8 @@ use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -204,9 +206,9 @@ public static function dataNativeUnionTypes(): array } /** - * @dataProvider dataNativeUnionTypes * @param list $errors */ + #[DataProvider('dataNativeUnionTypes')] public function testNativeUnionTypes(int $phpVersionId, array $errors): void { $this->phpVersionId = $phpVersionId; @@ -364,15 +366,12 @@ public static function dataRequiredParameterAfterOptional(): array } /** - * @dataProvider dataRequiredParameterAfterOptional * @param list $errors */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataRequiredParameterAfterOptional')] public function testRequiredParameterAfterOptional(int $phpVersionId, array $errors): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->phpVersionId = $phpVersionId; $this->analyse([__DIR__ . '/data/required-parameter-after-optional.php'], $errors); } @@ -406,9 +405,9 @@ public static function dataIntersectionTypes(): array } /** - * @dataProvider dataIntersectionTypes * @param list $errors */ + #[DataProvider('dataIntersectionTypes')] public function testIntersectionTypes(int $phpVersion, array $errors): void { $this->phpVersionId = $phpVersion; @@ -432,12 +431,9 @@ public function testTrueTypehint(): void $this->analyse([__DIR__ . '/data/true-typehint.php'], $errors); } + #[RequiresPhp('>= 8.0')] public function testConditionalReturnType(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/conditional-return-type.php'], [ [ 'Template type T of function FunctionConditionalReturnType\notGet() is not referenced in a parameter.', @@ -446,12 +442,9 @@ public function testConditionalReturnType(): void ]); } + #[RequiresPhp('>= 8.0')] public function testTemplateInParamOut(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/param-out.php'], [ [ 'Template type S of function ParamOutTemplate\uselessGeneric() is not referenced in a parameter.', diff --git a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php index 54fad29b4d..9db721eaee 100644 --- a/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php +++ b/tests/PHPStan/Rules/Functions/FunctionCallableRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -27,11 +28,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('< 8.1')] public function testNotSupportedOnOlderVersions(): void { - if (PHP_VERSION_ID >= 80100) { - self::markTestSkipped('Test runs on PHP < 8.1.'); - } $this->analyse([__DIR__ . '/data/function-callable-not-supported.php'], [ [ 'First-class callables are supported only on PHP 8.1 and later.', @@ -40,12 +39,9 @@ public function testNotSupportedOnOlderVersions(): void ]); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/function-callable.php'], [ [ 'Function nonexistent not found.', diff --git a/tests/PHPStan/Rules/Functions/ImplodeParameterCastableToStringRuleTest.php b/tests/PHPStan/Rules/Functions/ImplodeParameterCastableToStringRuleTest.php index 65194fa040..d0f1b9a809 100644 --- a/tests/PHPStan/Rules/Functions/ImplodeParameterCastableToStringRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ImplodeParameterCastableToStringRuleTest.php @@ -6,7 +6,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -20,12 +20,9 @@ protected function getRule(): Rule return new ImplodeParameterCastableToStringRule($broker, new ParameterCastableToStringCheck(new RuleLevelHelper($broker, true, false, true, true, true, false, true))); } + #[RequiresPhp('>= 8.0')] public function testNamedArguments(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/implode-param-castable-to-string-functions-named-args.php'], [ [ 'Parameter $array of function implode expects array, array> given.', @@ -46,12 +43,9 @@ public function testNamedArguments(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnum(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/implode-param-castable-to-string-functions-enum.php'], [ [ 'Parameter #2 $array of function implode expects array, array given.', diff --git a/tests/PHPStan/Rules/Functions/ParameterCastableToNumberRuleTest.php b/tests/PHPStan/Rules/Functions/ParameterCastableToNumberRuleTest.php index fbc5128807..588c845952 100644 --- a/tests/PHPStan/Rules/Functions/ParameterCastableToNumberRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ParameterCastableToNumberRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_map; use function str_replace; use const PHP_VERSION_ID; @@ -76,12 +77,9 @@ public function testRule(): void ])); } + #[RequiresPhp('>= 8.0')] public function testNamedArguments(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/param-castable-to-number-functions-named-args.php'], [ [ 'Parameter $array of function array_sum expects an array of values castable to number, array> given.', @@ -94,12 +92,9 @@ public function testNamedArguments(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnum(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/param-castable-to-number-functions-enum.php'], [ [ 'Parameter #1 $array of function array_sum expects an array of values castable to number, array given.', @@ -112,12 +107,9 @@ public function testEnum(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug11883(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-11883.php'], [ [ 'Parameter #1 $array of function array_sum expects an array of values castable to number, array given.', diff --git a/tests/PHPStan/Rules/Functions/ParameterCastableToStringRuleTest.php b/tests/PHPStan/Rules/Functions/ParameterCastableToStringRuleTest.php index 04eb4fb308..bfa7339c18 100644 --- a/tests/PHPStan/Rules/Functions/ParameterCastableToStringRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ParameterCastableToStringRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_map; use function str_replace; use const PHP_VERSION_ID; @@ -68,12 +69,9 @@ public function testRule(): void ])); } + #[RequiresPhp('>= 8.0')] public function testNamedArguments(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/param-castable-to-string-functions-named-args.php'], [ [ 'Parameter $keys of function array_combine expects an array of values castable to string, array> given.', @@ -86,12 +84,9 @@ public function testNamedArguments(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnum(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/param-castable-to-string-functions-enum.php'], [ [ 'Parameter #1 $array of function array_intersect expects an array of values castable to string, array given.', @@ -160,12 +155,9 @@ public function testBug3946(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug11111(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-11111.php'], [ [ 'Parameter #1 $keys of function array_fill_keys expects an array of values castable to string, array given.', @@ -178,12 +170,9 @@ public function testBug11111(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug11141(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-11141.php'], [ [ 'Parameter #1 $array of function array_diff expects an array of values castable to string, array given.', diff --git a/tests/PHPStan/Rules/Functions/ReturnNullsafeByRefRuleTest.php b/tests/PHPStan/Rules/Functions/ReturnNullsafeByRefRuleTest.php index a3b8f1db9e..46a1e0c17f 100644 --- a/tests/PHPStan/Rules/Functions/ReturnNullsafeByRefRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ReturnNullsafeByRefRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\NullsafeCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -36,12 +36,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/return-null-safe-by-ref-property-hooks.php'], [ [ 'Nullsafe cannot be returned by reference.', diff --git a/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php b/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php index 95566979c8..d4408b9839 100644 --- a/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php @@ -6,7 +6,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -225,23 +225,17 @@ public function testBug7766(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug8846(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->checkExplicitMixed = true; $this->checkNullables = true; $this->analyse([__DIR__ . '/data/bug-8846.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug10077(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->checkExplicitMixed = true; $this->checkNullables = true; $this->analyse([__DIR__ . '/data/bug-10077.php'], [ @@ -259,12 +253,9 @@ public function testBug8683(): void $this->analyse([__DIR__ . '/data/bug-8683.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug7984(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = true; $this->checkNullables = true; $this->analyse([__DIR__ . '/data/bug-7984.php'], []); diff --git a/tests/PHPStan/Rules/Functions/SortParameterCastableToStringRuleTest.php b/tests/PHPStan/Rules/Functions/SortParameterCastableToStringRuleTest.php index ea3ad2d00b..8193d5b6ef 100644 --- a/tests/PHPStan/Rules/Functions/SortParameterCastableToStringRuleTest.php +++ b/tests/PHPStan/Rules/Functions/SortParameterCastableToStringRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_map; use function str_replace; use const PHP_VERSION_ID; @@ -80,12 +81,9 @@ public function testRule(): void ])); } + #[RequiresPhp('>= 8.0')] public function testNamedArguments(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/sort-param-castable-to-string-functions-named-args.php'], [ [ 'Parameter $array of function array_unique expects an array of values castable to string, array> given.', @@ -110,12 +108,9 @@ public function testNamedArguments(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnum(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/sort-param-castable-to-string-functions-enum.php'], [ [ 'Parameter #1 $array of function array_unique expects an array of values castable to string, array given.', diff --git a/tests/PHPStan/Rules/Functions/UselessFunctionReturnValueRuleTest.php b/tests/PHPStan/Rules/Functions/UselessFunctionReturnValueRuleTest.php index 545bf6c061..c71f59ec2e 100644 --- a/tests/PHPStan/Rules/Functions/UselessFunctionReturnValueRuleTest.php +++ b/tests/PHPStan/Rules/Functions/UselessFunctionReturnValueRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -37,12 +37,9 @@ public function testUselessReturnValue(): void ]); } + #[RequiresPhp('>= 8.0')] public function testUselessReturnValuePhp8(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/useless-fn-return-php8.php'], [ [ 'Return value of function print_r() is always true and the result is printed instead of being returned. Pass in true as parameter #2 $return to return the output instead.', diff --git a/tests/PHPStan/Rules/Generics/ClassTemplateTypeRuleTest.php b/tests/PHPStan/Rules/Generics/ClassTemplateTypeRuleTest.php index e08f5e82b6..27ed122f68 100644 --- a/tests/PHPStan/Rules/Generics/ClassTemplateTypeRuleTest.php +++ b/tests/PHPStan/Rules/Generics/ClassTemplateTypeRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\ClassNameCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -139,11 +139,9 @@ public function testInInterface(): void $this->analyse([__DIR__ . '/data/interface-template.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug10049(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $this->analyse([__DIR__ . '/data/bug-10049.php'], [ [ 'PHPDoc tag @template for class Bug10049\SimpleEntity cannot have existing class Bug10049\SimpleEntity as its name.', diff --git a/tests/PHPStan/Rules/Generics/EnumAncestorsRuleTest.php b/tests/PHPStan/Rules/Generics/EnumAncestorsRuleTest.php index 41fc7bf0ce..070c8e3021 100644 --- a/tests/PHPStan/Rules/Generics/EnumAncestorsRuleTest.php +++ b/tests/PHPStan/Rules/Generics/EnumAncestorsRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -28,12 +28,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/enum-ancestors.php'], [ [ 'Enum EnumGenericAncestors\Foo has @implements tag, but does not implement any interface.', @@ -62,12 +59,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testCrossCheckInterfaces(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/cross-check-interfaces-enums.php'], [ [ 'Interface IteratorAggregate specifies template type TValue of interface Traversable as string but it\'s already specified as CrossCheckInterfacesEnums\Item.', diff --git a/tests/PHPStan/Rules/Generics/EnumTemplateTypeRuleTest.php b/tests/PHPStan/Rules/Generics/EnumTemplateTypeRuleTest.php index dbd82cf985..6028064d26 100644 --- a/tests/PHPStan/Rules/Generics/EnumTemplateTypeRuleTest.php +++ b/tests/PHPStan/Rules/Generics/EnumTemplateTypeRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -17,12 +17,9 @@ protected function getRule(): Rule return new EnumTemplateTypeRule(); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/enum-template.php'], [ [ 'Enum EnumTemplate\Foo has PHPDoc @template tag but enums cannot be generic.', diff --git a/tests/PHPStan/Rules/Generics/MethodSignatureVarianceRuleTest.php b/tests/PHPStan/Rules/Generics/MethodSignatureVarianceRuleTest.php index ec893f0947..81392060c2 100644 --- a/tests/PHPStan/Rules/Generics/MethodSignatureVarianceRuleTest.php +++ b/tests/PHPStan/Rules/Generics/MethodSignatureVarianceRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -235,12 +235,9 @@ public function testPr2465(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug10609(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-10609.php'], [ [ 'Template type A is declared as covariant, but occurs in contravariant position in parameter fn of method Bug10609\Collection::tap().', diff --git a/tests/PHPStan/Rules/Generics/PropertyVarianceRuleTest.php b/tests/PHPStan/Rules/Generics/PropertyVarianceRuleTest.php index 0708ec3095..8998d9712e 100644 --- a/tests/PHPStan/Rules/Generics/PropertyVarianceRuleTest.php +++ b/tests/PHPStan/Rules/Generics/PropertyVarianceRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -57,12 +57,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testPromoted(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/property-variance-promoted.php'], [ [ 'Template type X is declared as covariant, but occurs in invariant position in property PropertyVariance\Promoted\B::$a.', @@ -99,12 +96,9 @@ public function testPromoted(): void ]); } + #[RequiresPhp('>= 8.1')] public function testReadOnly(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/property-variance-readonly.php'], [ [ 'Template type X is declared as covariant, but occurs in contravariant position in property PropertyVariance\ReadOnly\B::$b.', diff --git a/tests/PHPStan/Rules/Keywords/ContinueBreakInLoopRuleTest.php b/tests/PHPStan/Rules/Keywords/ContinueBreakInLoopRuleTest.php index bca307593c..7c955e4c50 100644 --- a/tests/PHPStan/Rules/Keywords/ContinueBreakInLoopRuleTest.php +++ b/tests/PHPStan/Rules/Keywords/ContinueBreakInLoopRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -47,12 +47,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/continue-break-property-hook.php'], [ [ 'Keyword break used outside of a loop or a switch statement.', diff --git a/tests/PHPStan/Rules/Methods/AbstractMethodInNonAbstractClassRuleTest.php b/tests/PHPStan/Rules/Methods/AbstractMethodInNonAbstractClassRuleTest.php index 01c8541922..0800da059f 100644 --- a/tests/PHPStan/Rules/Methods/AbstractMethodInNonAbstractClassRuleTest.php +++ b/tests/PHPStan/Rules/Methods/AbstractMethodInNonAbstractClassRuleTest.php @@ -6,7 +6,7 @@ use Bug3406\ClassFoo; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -71,12 +71,9 @@ public function testNonAbstractMethodWithNoBody(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnum(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/method-in-enum-without-body.php'], [ [ 'Non-abstract method MethodInEnumWithoutBody\Foo::doFoo() must contain a body.', @@ -89,12 +86,9 @@ public function testEnum(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug11592(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1'); - } - $this->analyse([__DIR__ . '/../Classes/data/bug-11592.php'], [ [ 'Enum Bug11592\Test contains abstract method from().', diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index 9c22e7df46..47b6db7189 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -9,6 +9,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -37,24 +39,18 @@ protected function getRule(): Rule ); } + #[RequiresPhp('< 8.0')] public function testIsCallablePhp7(): void { - if (PHP_VERSION_ID >= 80000) { - $this->markTestSkipped('Test requires PHP 7.0'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; $this->analyse([ __DIR__ . '/data/call-methods-is-callable.php'], []); } + #[RequiresPhp('>= 8.0')] public function testIsCallablePhp8(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -1321,9 +1317,7 @@ public static function dataIterable(): array ]; } - /** - * @dataProvider dataIterable - */ + #[DataProvider('dataIterable')] public function testIterables(bool $checkNullables): void { $this->checkThisOnly = false; @@ -1593,15 +1587,12 @@ public static function dataExplicitMixed(): array } /** - * @dataProvider dataExplicitMixed * @param list $errors */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataExplicitMixed')] public function testExplicitMixed(bool $checkExplicitMixed, array $errors): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -1637,9 +1628,9 @@ public static function dataImplicitMixed(): array } /** - * @dataProvider dataImplicitMixed * @param list $errors */ + #[DataProvider('dataImplicitMixed')] public function testImplicitMixed(bool $checkImplicitMixed, array $errors): void { $this->checkThisOnly = false; @@ -1729,12 +1720,9 @@ public function testBug3683(): void ]); } + #[RequiresPhp('>= 8.0')] public function testStringable(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -1801,12 +1789,9 @@ public function testNullSafe(): void ]); } + #[RequiresPhp('< 8.0')] public function testDisallowNamedArguments(): void { - if (PHP_VERSION_ID >= 80000) { - $this->markTestSkipped('Test requires PHP earlier than 8.0.'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -1833,12 +1818,9 @@ public function testDisallowNamedArgumentsInPhpVersionScope(): void ]); } + #[RequiresPhp('>= 8.0')] public function testNamedArguments(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -2113,16 +2095,13 @@ public function testBug3546(): void $this->analyse([__DIR__ . '/data/bug-3546.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug4800(): void { $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/bug-4800.php'], [ [ 'Missing parameter $bar (string) in call to method Bug4800\HelloWorld2::a().', @@ -2363,12 +2342,9 @@ public function testBug3465(): void $this->analyse([__DIR__ . '/data/bug-3465.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug5868(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -2406,12 +2382,9 @@ public function testFirstClassCallable(): void $this->analyse([__DIR__ . '/data/first-class-method-callable.php'], []); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -2456,12 +2429,9 @@ public function testEnums(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug6239(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('This test needs PHP 8.0'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -2489,12 +2459,9 @@ public function testRectorDoWhileVarIssue(): void ]); } + #[RequiresPhp('>= 8.1')] public function testReadOnlyPropertyPassedByReference(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -2537,12 +2504,9 @@ public function testBug6236(): void $this->analyse([__DIR__ . '/data/bug-6236.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug6118(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -2658,12 +2622,9 @@ public function testGenericVariance(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug6904(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -2720,12 +2681,9 @@ public function testConditionalComplexTemplates(): void $this->analyse([__DIR__ . '/data/conditional-complex-templates.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug6291(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -2742,12 +2700,9 @@ public function testBug1517(): void $this->analyse([__DIR__ . '/data/bug-1517.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug7593(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -2782,11 +2737,9 @@ public function testBug7600(): void $this->analyse([__DIR__ . '/data/bug-7600.php'], []); } + #[RequiresPhp('>= 8.2')] public function testBug8058(): void { - if (PHP_VERSION_ID < 80200) { - $this->markTestSkipped('Test requires PHP 8.2'); - } $this->checkThisOnly = false; $this->checkNullables = false; $this->checkUnionTypes = false; @@ -2794,11 +2747,9 @@ public function testBug8058(): void $this->analyse([__DIR__ . '/data/bug-8058.php'], []); } + #[RequiresPhp('< 8.2')] public function testBug8058b(): void { - if (PHP_VERSION_ID >= 80200) { - $this->markTestSkipped('Test requires PHP before 8.2'); - } $this->checkThisOnly = false; $this->checkNullables = false; $this->checkUnionTypes = false; @@ -2930,9 +2881,9 @@ public static function dataCallablesWithoutCheckNullables(): iterable } /** - * @dataProvider dataCallablesWithoutCheckNullables * @param list $expectedErrors */ + #[DataProvider('dataCallablesWithoutCheckNullables')] public function testCallablesWithoutCheckNullables(bool $checkNullables, bool $checkUnionTypes, array $expectedErrors): void { $this->checkThisOnly = false; @@ -2941,12 +2892,9 @@ public function testCallablesWithoutCheckNullables(bool $checkNullables, bool $c $this->analyse([__DIR__ . '/data/callables-without-check-nullables.php'], $expectedErrors); } + #[RequiresPhp('>= 8.0')] public function testBug8713(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -3140,12 +3088,9 @@ public function testObjectShapes(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug9951(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -3162,12 +3107,9 @@ public function testBug9951(): void ]); } + #[RequiresPhp('>= 8.3')] public function testTypedClassConstants(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -3175,12 +3117,9 @@ public function testTypedClassConstants(): void $this->analyse([__DIR__ . '/data/return-type-class-constant.php'], []); } + #[RequiresPhp('>= 8.0')] public function testNamedParametersForMultiVariantFunctions(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -3273,12 +3212,9 @@ public function testBug6371(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBugTemplateMixedUnionIntersect(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -3380,12 +3316,9 @@ public function testClosureParameterGenerics(): void $this->analyse([__DIR__ . '/data/closure-parameter-generics.php'], []); } + #[RequiresPhp('>= 8.0')] public function testNoNamedArguments(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; @@ -3529,12 +3462,9 @@ public function testBug12691(): void $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-12691.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug12422(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1.'); - } - $this->checkThisOnly = false; $this->checkNullables = true; $this->checkUnionTypes = true; diff --git a/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php index 8c35bc05f8..282415af6f 100644 --- a/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php @@ -12,9 +12,10 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_merge; use function usort; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -411,14 +412,11 @@ public function testBug2164(): void ]); } + #[RequiresPhp('>= 8.0')] public function testNamedArguments(): void { $this->checkThisOnly = false; - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/static-method-named-arguments.php'], [ [ 'Missing parameter $j (int) in call to static method StaticMethodNamedArguments\Foo::doFoo().', @@ -452,12 +450,9 @@ public function testBug4550(): void ]); } + #[RequiresPhp('< 8.0')] public function testBug1971(): void { - if (PHP_VERSION_ID >= 80000) { - $this->markTestSkipped('Test requires PHP 7.x'); - } - $this->checkThisOnly = false; $this->analyse([__DIR__ . '/data/bug-1971.php'], [ [ @@ -467,12 +462,9 @@ public function testBug1971(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug1971Php8(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->checkThisOnly = false; $this->analyse([__DIR__ . '/data/bug-1971.php'], [ [ @@ -757,27 +749,21 @@ public static function dataMixed(): array } /** - * @dataProvider dataMixed * @param list $errors */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataMixed')] public function testMixed(bool $checkExplicitMixed, bool $checkImplicitMixed, array $errors): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkThisOnly = false; $this->checkExplicitMixed = $checkExplicitMixed; $this->checkImplicitMixed = $checkImplicitMixed; $this->analyse([__DIR__ . '/data/call-static-method-mixed.php'], $errors); } + #[RequiresPhp('>= 8.1')] public function testBugWrongMethodNameWithTemplateMixed(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1'); - } - $this->checkThisOnly = false; $this->checkExplicitMixed = true; $this->checkImplicitMixed = true; diff --git a/tests/PHPStan/Rules/Methods/ExistingClassesInTypehintsRuleTest.php b/tests/PHPStan/Rules/Methods/ExistingClassesInTypehintsRuleTest.php index 4c782cfcbb..7342558234 100644 --- a/tests/PHPStan/Rules/Methods/ExistingClassesInTypehintsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/ExistingClassesInTypehintsRuleTest.php @@ -10,6 +10,8 @@ use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -198,9 +200,9 @@ public static function dataNativeUnionTypes(): array } /** - * @dataProvider dataNativeUnionTypes * @param list $errors */ + #[DataProvider('dataNativeUnionTypes')] public function testNativeUnionTypes(int $phpVersionId, array $errors): void { $this->phpVersionId = $phpVersionId; @@ -358,15 +360,12 @@ public static function dataRequiredParameterAfterOptional(): array } /** - * @dataProvider dataRequiredParameterAfterOptional * @param list $errors */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataRequiredParameterAfterOptional')] public function testRequiredParameterAfterOptional(int $phpVersionId, array $errors): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->phpVersionId = $phpVersionId; $this->analyse([__DIR__ . '/data/required-parameter-after-optional.php'], $errors); } @@ -410,9 +409,9 @@ public static function dataIntersectionTypes(): array } /** - * @dataProvider dataIntersectionTypes * @param list $errors */ + #[DataProvider('dataIntersectionTypes')] public function testIntersectionTypes(int $phpVersion, array $errors): void { $this->phpVersionId = $phpVersion; @@ -420,12 +419,9 @@ public function testIntersectionTypes(int $phpVersion, array $errors): void $this->analyse([__DIR__ . '/data/intersection-types.php'], $errors); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/enums-typehints.php'], [ [ 'Parameter $int of method EnumsTypehints\Foo::doFoo() has invalid type EnumsTypehints\intt.', @@ -497,12 +493,9 @@ public function testTrueTypehint(): void $this->analyse([__DIR__ . '/data/true-typehint.php'], $errors); } + #[RequiresPhp('>= 8.0')] public function testConditionalReturnType(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/conditional-return-type.php'], [ [ 'Template type T of method MethodConditionalReturnType\Container::notGet() is not referenced in a parameter.', @@ -516,12 +509,9 @@ public function testBug7519(): void $this->analyse([__DIR__ . '/data/bug-7519.php'], []); } + #[RequiresPhp('>= 8.0')] public function testTemplateInParamOut(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/param-out.php'], [ [ 'Template type T of method ParamOutTemplate\FooBar::uselessLocalTemplate() is not referenced in a parameter.', @@ -584,12 +574,9 @@ public function testSelfOut(): void ]); } + #[RequiresPhp('>= 8.4')] public function testDeprecatedImplicitlyNullableParameterType(): void { - if (PHP_VERSION_ID < 80400) { - self::markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/method-implicitly-nullable.php'], [ [ 'Deprecated in PHP 8.4: Parameter #3 $c (int) is implicitly nullable via default value null.', @@ -606,11 +593,9 @@ public function testDeprecatedImplicitlyNullableParameterType(): void ]); } + #[RequiresPhp('>= 8.4')] public function testBug12501(): void { - if (PHP_VERSION_ID < 80400) { - self::markTestSkipped('This test needs PHP 8.4.'); - } $this->analyse([__DIR__ . '/data/bug-12501.php'], []); } diff --git a/tests/PHPStan/Rules/Methods/FinalPrivateMethodRuleTest.php b/tests/PHPStan/Rules/Methods/FinalPrivateMethodRuleTest.php index 9c56dbcb36..e9def238c3 100644 --- a/tests/PHPStan/Rules/Methods/FinalPrivateMethodRuleTest.php +++ b/tests/PHPStan/Rules/Methods/FinalPrivateMethodRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use const PHP_VERSION_ID; /** @extends RuleTestCase */ @@ -36,9 +37,9 @@ public static function dataRule(): array } /** - * @dataProvider dataRule * @param list $errors */ + #[DataProvider('dataRule')] public function testRule(int $phpVersion, array $errors): void { $testVersion = new PhpVersion($phpVersion); diff --git a/tests/PHPStan/Rules/Methods/IncompatibleDefaultParameterTypeRuleTest.php b/tests/PHPStan/Rules/Methods/IncompatibleDefaultParameterTypeRuleTest.php index 0f6d5b81f1..df7e897d77 100644 --- a/tests/PHPStan/Rules/Methods/IncompatibleDefaultParameterTypeRuleTest.php +++ b/tests/PHPStan/Rules/Methods/IncompatibleDefaultParameterTypeRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -74,12 +74,9 @@ public function testDefaultValueForPromotedProperty(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug10956(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-10956.php'], []); } diff --git a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php index 19f26d13b9..6dcf45e242 100644 --- a/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -27,11 +28,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('< 8.1')] public function testNotSupportedOnOlderVersions(): void { - if (PHP_VERSION_ID >= 80100) { - self::markTestSkipped('Test runs on PHP < 8.1.'); - } $this->analyse([__DIR__ . '/data/method-callable-not-supported.php'], [ [ 'First-class callables are supported only on PHP 8.1 and later.', @@ -40,12 +39,9 @@ public function testNotSupportedOnOlderVersions(): void ]); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/method-callable.php'], [ [ 'Call to method MethodCallable\Foo::doFoo() with incorrect case: dofoo', diff --git a/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php b/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php index 4d18dcd7fb..b23da34309 100644 --- a/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Reflection\Php\PhpClassReflectionExtension; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -377,12 +378,9 @@ public function testOverridenMethodWithConditionalReturnType(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug7652(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->reportMaybes = true; $this->reportStatic = true; $this->analyse([__DIR__ . '/data/bug-7652.php'], [ @@ -452,12 +450,9 @@ public function testBug9905(): void $this->analyse([__DIR__ . '/data/bug-9905.php'], []); } + #[RequiresPhp('>= 8.0')] public function testTraits(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->reportMaybes = true; $this->reportStatic = true; @@ -469,12 +464,9 @@ public function testTraits(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug10166(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->reportMaybes = true; $this->reportStatic = true; @@ -486,12 +478,9 @@ public function testBug10166(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug10184(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->reportMaybes = true; $this->reportStatic = true; @@ -530,12 +519,9 @@ public function testBug3580(): void $this->analyse([__DIR__ . '/data/bug-3580.php'], []); } + #[RequiresPhp('>= 8.0')] public function testOverridenAbstractTraitMethodPhpDoc(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->reportMaybes = true; $this->reportStatic = true; $this->analyse([__DIR__ . '/data/overriden-abstract-trait-method-phpdoc.php'], []); @@ -548,34 +534,25 @@ public function testGenericStaticType(): void $this->analyse([__DIR__ . '/data/method-signature-generic-static-type.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug10240(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->reportMaybes = true; $this->reportStatic = true; $this->analyse([__DIR__ . '/data/bug-10240.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug10488(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->reportMaybes = true; $this->reportStatic = true; $this->analyse([__DIR__ . '/data/bug-10488.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug12073(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->reportMaybes = true; $this->reportStatic = true; $this->analyse([__DIR__ . '/data/bug-12073.php'], []); diff --git a/tests/PHPStan/Rules/Methods/MissingMagicSerializationMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/MissingMagicSerializationMethodsRuleTest.php index 989d8e0a52..ad3c23c992 100644 --- a/tests/PHPStan/Rules/Methods/MissingMagicSerializationMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MissingMagicSerializationMethodsRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -18,12 +19,9 @@ protected function getRule(): Rule return new MissingMagicSerializationMethodsRule(new PhpVersion(PHP_VERSION_ID)); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/missing-serialization.php'], [ [ 'Non-abstract class MissingMagicSerializationMethods\myObj implements the Serializable interface, but does not implement __serialize().', diff --git a/tests/PHPStan/Rules/Methods/MissingMethodImplementationRuleTest.php b/tests/PHPStan/Rules/Methods/MissingMethodImplementationRuleTest.php index babaadaae2..ff51b465e8 100644 --- a/tests/PHPStan/Rules/Methods/MissingMethodImplementationRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MissingMethodImplementationRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -45,12 +45,9 @@ public function testBug3958(): void $this->analyse([__DIR__ . '/data/bug-3958.php'], []); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/missing-method-impl-enum.php'], [ [ 'Enum MissingMethodImplEnum\Bar contains abstract method doFoo() from interface MissingMethodImplEnum\FooInterface.', diff --git a/tests/PHPStan/Rules/Methods/MissingMethodReturnTypehintRuleTest.php b/tests/PHPStan/Rules/Methods/MissingMethodReturnTypehintRuleTest.php index 572b38c33a..dc0f1b7931 100644 --- a/tests/PHPStan/Rules/Methods/MissingMethodReturnTypehintRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MissingMethodReturnTypehintRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\MissingTypehintCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -112,12 +112,9 @@ public function testGenericStatic(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug9657(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/bug-9657.php'], []); } diff --git a/tests/PHPStan/Rules/Methods/NullsafeMethodCallRuleTest.php b/tests/PHPStan/Rules/Methods/NullsafeMethodCallRuleTest.php index 5c308ea5ad..ff7b48186a 100644 --- a/tests/PHPStan/Rules/Methods/NullsafeMethodCallRuleTest.php +++ b/tests/PHPStan/Rules/Methods/NullsafeMethodCallRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -37,21 +37,15 @@ public function testBug8664(): void $this->analyse([__DIR__ . '/../../Analyser/data/bug-8664.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug9293(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-9293.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug6922b(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-6922b.php'], []); } diff --git a/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php b/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php index 9252e335f2..e55c5011fd 100644 --- a/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php +++ b/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php @@ -6,6 +6,8 @@ use PHPStan\Reflection\Php\PhpClassReflectionExtension; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_filter; use function array_values; use const PHP_VERSION_ID; @@ -53,9 +55,7 @@ public static function dataOverridingFinalMethod(): array ]; } - /** - * @dataProvider dataOverridingFinalMethod - */ + #[DataProvider('dataOverridingFinalMethod')] public function testOverridingFinalMethod(int $phpVersion, string $contravariantMessage): void { $errors = [ @@ -228,19 +228,16 @@ public static function dataParameterContravariance(): array } /** - * @dataProvider dataParameterContravariance * @param list $expectedErrors */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataParameterContravariance')] public function testParameterContravariance( string $file, int $phpVersion, array $expectedErrors, ): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->phpVersionId = $phpVersion; $this->analyse([$file], $expectedErrors); } @@ -290,9 +287,9 @@ public static function dataReturnTypeCovariance(): array } /** - * @dataProvider dataReturnTypeCovariance * @param list $expectedErrors */ + #[DataProvider('dataReturnTypeCovariance')] public function testReturnTypeCovariance( int $phpVersion, array $expectedErrors, @@ -302,9 +299,7 @@ public function testReturnTypeCovariance( $this->analyse([__DIR__ . '/data/return-type-covariance.php'], $expectedErrors); } - /** - * @dataProvider dataOverridingFinalMethod - */ + #[DataProvider('dataOverridingFinalMethod')] public function testParle(int $phpVersion, string $contravariantMessage, string $covariantMessage): void { $this->phpVersionId = $phpVersion; @@ -326,9 +321,7 @@ public function testVariadicParameterIsAlwaysOptional(): void $this->analyse([__DIR__ . '/data/variadic-always-optional.php'], []); } - /** - * @dataProvider dataOverridingFinalMethod - */ + #[DataProvider('dataOverridingFinalMethod')] public function testBug3403(int $phpVersion): void { $this->phpVersionId = $phpVersion; @@ -435,9 +428,9 @@ public static function dataLessOverridenParametersWithVariadic(): array } /** - * @dataProvider dataLessOverridenParametersWithVariadic * @param list $errors */ + #[DataProvider('dataLessOverridenParametersWithVariadic')] public function testLessOverridenParametersWithVariadic(int $phpVersionId, array $errors): void { $this->phpVersionId = $phpVersionId; @@ -464,9 +457,9 @@ public static function dataParameterTypeWidening(): array } /** - * @dataProvider dataParameterTypeWidening * @param list $errors */ + #[DataProvider('dataParameterTypeWidening')] public function testParameterTypeWidening(int $phpVersionId, array $errors): void { $this->phpVersionId = $phpVersionId; @@ -528,9 +521,9 @@ public static function dataTentativeReturnTypes(): array } /** - * @dataProvider dataTentativeReturnTypes * @param list $errors */ + #[DataProvider('dataTentativeReturnTypes')] public function testTentativeReturnTypes(int $phpVersionId, array $errors): void { if (PHP_VERSION_ID < 80100) { @@ -574,12 +567,9 @@ public function testBug9391(): void $this->analyse([__DIR__ . '/data/bug-9391.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBugWithIndirectPrototype(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->phpVersionId = PHP_VERSION_ID; $this->analyse([__DIR__ . '/data/overriding-indirect-prototype.php'], [ [ @@ -674,12 +664,9 @@ public function testBug10101(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug9615(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $tipText = 'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.'; $this->phpVersionId = PHP_VERSION_ID; @@ -739,12 +726,9 @@ public function testTraits(): void $this->analyse([__DIR__ . '/data/overriding-trait-methods.php'], $errors); } + #[RequiresPhp('>= 8.3')] public function testOverrideAttribute(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->phpVersionId = PHP_VERSION_ID; $this->analyse([__DIR__ . '/data/override-attribute.php'], [ [ @@ -776,9 +760,9 @@ public static function dataCheckMissingOverrideAttribute(): iterable } /** - * @dataProvider dataCheckMissingOverrideAttribute * @param list $errors */ + #[DataProvider('dataCheckMissingOverrideAttribute')] public function testCheckMissingOverrideAttribute(bool $checkMissingOverrideMethodAttribute, int $phpVersionId, array $errors): void { $this->checkMissingOverrideMethodAttribute = $checkMissingOverrideMethodAttribute; @@ -801,12 +785,9 @@ public function testBug10153(): void $this->analyse([__DIR__ . '/data/bug-10153.php'], $errors); } + #[RequiresPhp('>= 8.3')] public function testBug12471(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->checkMissingOverrideMethodAttribute = true; $this->phpVersionId = PHP_VERSION_ID; $this->analyse([__DIR__ . '/data/bug-12471.php'], []); @@ -824,22 +805,16 @@ public function testBug9524(): void $this->analyse([__DIR__ . '/data/bug-9524.php'], []); } + #[RequiresPhp('>= 8.0')] public function testSimpleXmlElementChildClass(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->phpVersionId = PHP_VERSION_ID; $this->analyse([__DIR__ . '/data/simple-xml-element-child.php'], []); } + #[RequiresPhp('>= 8.3')] public function testFixOverride(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->phpVersionId = PHP_VERSION_ID; $this->checkMissingOverrideMethodAttribute = true; $this->fix(__DIR__ . '/data/fix-override-attribute.php', __DIR__ . '/data/fix-override-attribute.php.fixed'); diff --git a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php index ead208531f..4eea9d6a5b 100644 --- a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php @@ -6,6 +6,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -302,12 +304,9 @@ public function testMisleadingMixedType(): void $this->analyse([__DIR__ . '/data/method-misleading-mixed-return.php'], $errors); } + #[RequiresPhp('>= 8.0')] public function testMisleadingTypehintsInClassWithoutNamespace(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/misleadingTypehints.php'], [ [ 'Method FooWithoutNamespace::misleadingBoolReturnType() should return boolean but returns true.', @@ -548,12 +547,9 @@ public function testBug2573(): void $this->analyse([__DIR__ . '/data/bug-2573-return.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug4603(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-4603.php'], []); } @@ -592,9 +588,9 @@ public static function dataBug5218(): array } /** - * @dataProvider dataBug5218 * @param list $errors */ + #[DataProvider('dataBug5218')] public function testBug5218(bool $checkExplicitMixed, array $errors): void { $this->checkExplicitMixed = $checkExplicitMixed; @@ -776,12 +772,9 @@ public function testTaggedUnions(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug7904(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = true; $this->analyse([__DIR__ . '/data/bug-7904.php'], []); } @@ -804,12 +797,9 @@ public function testBug6358(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug8071(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = true; $this->analyse([__DIR__ . '/data/bug-8071.php'], [ [ @@ -1126,12 +1116,9 @@ public function testBug12223(): void $this->analyse([__DIR__ . '/data/bug-12223.php'], []); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - self::markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/property-hooks-return.php'], [ [ 'Get hook for property PropertyHooksReturn\Foo::$i should return int but returns string.', @@ -1163,12 +1150,9 @@ public function testPropertyHooks(): void ]); } + #[RequiresPhp('>= 8.4')] public function testShortGetPropertyHook(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/short-get-property-hook-return.php'], [ [ 'Get hook for property ShortGetPropertyHookReturn\Foo::$i should return int but returns string.', @@ -1196,12 +1180,9 @@ public function testShortGetPropertyHook(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug1O580(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-10580.php'], [ [ 'Method Bug10580\FooA::fooThisInterface() should return $this(Bug10580\FooA) but returns Bug10580\FooA.', @@ -1242,12 +1223,9 @@ public function testBug1O580(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug4443(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-4443.php'], [ [ 'Method Bug4443\HelloWorld::getArray() should return array but returns array|null.', diff --git a/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php b/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php index 0afd0f7f0f..2511b87083 100644 --- a/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php +++ b/tests/PHPStan/Rules/Methods/StaticMethodCallableRuleTest.php @@ -9,6 +9,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -42,12 +43,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('< 8.1')] public function testNotSupportedOnOlderVersions(): void { - if (PHP_VERSION_ID >= 80100) { - self::markTestSkipped('Test runs on PHP < 8.1.'); - } - $this->analyse([__DIR__ . '/data/static-method-callable-not-supported.php'], [ [ 'First-class callables are supported only on PHP 8.1 and later.', @@ -56,12 +54,9 @@ public function testNotSupportedOnOlderVersions(): void ]); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/static-method-callable.php'], [ [ 'Call to static method StaticMethodCallable\Foo::doFoo() with incorrect case: dofoo', diff --git a/tests/PHPStan/Rules/Missing/MissingReturnRuleTest.php b/tests/PHPStan/Rules/Missing/MissingReturnRuleTest.php index 08d9571499..b848a761d7 100644 --- a/tests/PHPStan/Rules/Missing/MissingReturnRuleTest.php +++ b/tests/PHPStan/Rules/Missing/MissingReturnRuleTest.php @@ -4,7 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -153,12 +154,9 @@ public function testMissingMixedReturnInEmptyBody(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug3488(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->checkExplicitMixedMissingReturn = true; $this->analyse([__DIR__ . '/data/bug-3488.php'], []); } @@ -260,15 +258,12 @@ public static function dataCheckPhpDocMissingReturn(): array } /** - * @dataProvider dataCheckPhpDocMissingReturn * @param list $errors */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataCheckPhpDocMissingReturn')] public function testCheckPhpDocMissingReturn(bool $checkPhpDocMissingReturn, array $errors): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixedMissingReturn = true; $this->checkPhpDocMissingReturn = $checkPhpDocMissingReturn; $this->analyse([__DIR__ . '/data/check-phpdoc-missing-return.php'], $errors); @@ -286,15 +281,10 @@ public static function dataModelMixin(): array ]; } - /** - * @dataProvider dataModelMixin - */ + #[RequiresPhp('>= 8.0')] + #[DataProvider('dataModelMixin')] public function testModelMixin(bool $checkExplicitMixedMissingReturn): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixedMissingReturn = $checkExplicitMixedMissingReturn; $this->checkPhpDocMissingReturn = true; $this->analyse([__DIR__ . '/../../Analyser/nsrt/model-mixin.php'], [ @@ -305,11 +295,9 @@ public function testModelMixin(bool $checkExplicitMixedMissingReturn): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug6257(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } $this->checkExplicitMixedMissingReturn = true; $this->checkPhpDocMissingReturn = true; $this->analyse([__DIR__ . '/data/bug-6257.php'], [ @@ -351,12 +339,9 @@ public function testBug9374(): void $this->analyse([__DIR__ . '/data/bug-9374.php'], []); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->checkExplicitMixedMissingReturn = true; $this->analyse([__DIR__ . '/data/property-hooks-missing-return.php'], [ [ @@ -381,12 +366,9 @@ public function testBug3488Two(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug12722(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->checkExplicitMixedMissingReturn = true; $this->analyse([__DIR__ . '/data/bug-12722.php'], []); } diff --git a/tests/PHPStan/Rules/Operators/InvalidBinaryOperationRuleTest.php b/tests/PHPStan/Rules/Operators/InvalidBinaryOperationRuleTest.php index 068b4c84e3..840bd8b450 100644 --- a/tests/PHPStan/Rules/Operators/InvalidBinaryOperationRuleTest.php +++ b/tests/PHPStan/Rules/Operators/InvalidBinaryOperationRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -284,12 +284,9 @@ public function testBug8827(): void $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-8827.php'], []); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/invalid-binary-nullsafe.php'], [ [ 'Binary operation "+" between array|null and \'2\' results in an error.', @@ -303,12 +300,9 @@ public function testBug5309(): void $this->analyse([__DIR__ . '/data/bug-5309.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBinaryMixed(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = true; $this->checkImplicitMixed = true; $this->analyse([__DIR__ . '/data/invalid-binary-mixed.php'], [ diff --git a/tests/PHPStan/Rules/Operators/InvalidComparisonOperationRuleTest.php b/tests/PHPStan/Rules/Operators/InvalidComparisonOperationRuleTest.php index d91141d5e6..f8163f171b 100644 --- a/tests/PHPStan/Rules/Operators/InvalidComparisonOperationRuleTest.php +++ b/tests/PHPStan/Rules/Operators/InvalidComparisonOperationRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -154,12 +154,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/invalid-comparison-nullsafe.php'], [ [ 'Comparison operation "==" between stdClass|null and int results in an error.', diff --git a/tests/PHPStan/Rules/Operators/InvalidIncDecOperationRuleTest.php b/tests/PHPStan/Rules/Operators/InvalidIncDecOperationRuleTest.php index 99be7a4e32..4faae03e3c 100644 --- a/tests/PHPStan/Rules/Operators/InvalidIncDecOperationRuleTest.php +++ b/tests/PHPStan/Rules/Operators/InvalidIncDecOperationRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -66,12 +66,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testMixed(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = true; $this->checkImplicitMixed = true; $this->analyse([__DIR__ . '/data/invalid-inc-dec-mixed.php'], [ diff --git a/tests/PHPStan/Rules/Operators/InvalidUnaryOperationRuleTest.php b/tests/PHPStan/Rules/Operators/InvalidUnaryOperationRuleTest.php index 009bc167d0..7300106db7 100644 --- a/tests/PHPStan/Rules/Operators/InvalidUnaryOperationRuleTest.php +++ b/tests/PHPStan/Rules/Operators/InvalidUnaryOperationRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -94,12 +94,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testMixed(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkImplicitMixed = true; $this->checkExplicitMixed = true; $this->analyse([__DIR__ . '/data/invalid-unary-mixed.php'], [ diff --git a/tests/PHPStan/Rules/PhpDoc/IncompatibleClassConstantPhpDocTypeRuleTest.php b/tests/PHPStan/Rules/PhpDoc/IncompatibleClassConstantPhpDocTypeRuleTest.php index 91a74e428b..1bd66e2600 100644 --- a/tests/PHPStan/Rules/PhpDoc/IncompatibleClassConstantPhpDocTypeRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/IncompatibleClassConstantPhpDocTypeRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Generics\GenericObjectTypeCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -32,12 +32,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.3')] public function testNativeType(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->analyse([__DIR__ . '/data/incompatible-class-constant-phpdoc-native-type.php'], [ [ 'PHPDoc tag @var for constant IncompatibleClassConstantPhpDocNativeType\Foo::BAZ with type string is incompatible with native type int.', @@ -50,12 +47,9 @@ public function testNativeType(): void ]); } + #[RequiresPhp('>= 8.3')] public function testBug10911(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->analyse([__DIR__ . '/data/bug-10911.php'], []); } diff --git a/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php b/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php index 57df9d3f7f..dae341a690 100644 --- a/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php @@ -10,7 +10,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; use PHPStan\Type\FileTypeMapper; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -232,12 +232,9 @@ public function testTemplateTypeNativeTypeObject(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/generic-enum-param.php'], [ [ 'PHPDoc tag @param for parameter $e contains generic type GenericEnumParam\FooEnum but enum GenericEnumParam\FooEnum is not generic.', @@ -246,12 +243,9 @@ public function testEnums(): void ]); } + #[RequiresPhp('>= 8.1')] public function testValueOfEnum(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/value-of-enum.php'], [ [ 'PHPDoc tag @param for parameter $shouldError with type string is incompatible with native type int.', @@ -264,12 +258,9 @@ public function testValueOfEnum(): void ]); } + #[RequiresPhp('>= 8.0')] public function testConditionalReturnType(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('This test needs PHP 8.0'); - } - $this->analyse([__DIR__ . '/data/incompatible-conditional-return-type.php'], [ [ 'PHPDoc tag @return with type ($p is int ? int : string) is not subtype of native type int.', diff --git a/tests/PHPStan/Rules/PhpDoc/IncompatiblePropertyHookPhpDocTypeRuleTest.php b/tests/PHPStan/Rules/PhpDoc/IncompatiblePropertyHookPhpDocTypeRuleTest.php index a28fe86d32..8dd6faa5d2 100644 --- a/tests/PHPStan/Rules/PhpDoc/IncompatiblePropertyHookPhpDocTypeRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/IncompatiblePropertyHookPhpDocTypeRuleTest.php @@ -10,7 +10,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; use PHPStan\Type\FileTypeMapper; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -46,12 +46,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.4')] public function testRule(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/incompatible-property-hook-phpdoc-types.php'], [ [ 'PHPDoc tag @return with type string is incompatible with native type int.', diff --git a/tests/PHPStan/Rules/PhpDoc/InvalidPHPStanDocTagRuleTest.php b/tests/PHPStan/Rules/PhpDoc/InvalidPHPStanDocTagRuleTest.php index e91e647054..6b5ba10a37 100644 --- a/tests/PHPStan/Rules/PhpDoc/InvalidPHPStanDocTagRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/InvalidPHPStanDocTagRuleTest.php @@ -6,7 +6,7 @@ use PHPStan\PhpDocParser\Parser\PhpDocParser; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -53,12 +53,9 @@ public function testBug8697(): void $this->analyse([__DIR__ . '/data/bug-8697.php'], []); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/invalid-phpstan-tag-property-hooks.php'], [ [ 'Unknown PHPDoc tag: @phpstan-what', diff --git a/tests/PHPStan/Rules/PhpDoc/InvalidPhpDocTagValueRuleTest.php b/tests/PHPStan/Rules/PhpDoc/InvalidPhpDocTagValueRuleTest.php index be63bff8e2..81c0868e3e 100644 --- a/tests/PHPStan/Rules/PhpDoc/InvalidPhpDocTagValueRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/InvalidPhpDocTagValueRuleTest.php @@ -6,7 +6,7 @@ use PHPStan\PhpDocParser\Parser\PhpDocParser; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -145,12 +145,9 @@ public function testBug6692(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/invalid-phpdoc-property-hooks.php'], [ [ 'PHPDoc tag @return has invalid value (Test(): Unexpected token "(", expected TOKEN_HORIZONTAL_WS at offset 16 on line 1', diff --git a/tests/PHPStan/Rules/PhpDoc/InvalidPhpDocVarTagTypeRuleTest.php b/tests/PHPStan/Rules/PhpDoc/InvalidPhpDocVarTagTypeRuleTest.php index e7a54bfc77..1c3f33d575 100644 --- a/tests/PHPStan/Rules/PhpDoc/InvalidPhpDocVarTagTypeRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/InvalidPhpDocVarTagTypeRuleTest.php @@ -10,7 +10,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; use PHPStan\Type\FileTypeMapper; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -158,11 +158,9 @@ public function testBug4486Namespace(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug6252(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } $this->analyse([__DIR__ . '/data/bug-6252.php'], []); } diff --git a/tests/PHPStan/Rules/PhpDoc/InvalidThrowsPhpDocValueRuleTest.php b/tests/PHPStan/Rules/PhpDoc/InvalidThrowsPhpDocValueRuleTest.php index acfcb569a9..60cf6874c7 100644 --- a/tests/PHPStan/Rules/PhpDoc/InvalidThrowsPhpDocValueRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/InvalidThrowsPhpDocValueRuleTest.php @@ -9,7 +9,8 @@ use PHPStan\Testing\RuleTestCase; use PHPStan\Type\FileTypeMapper; use PHPStan\Type\VerbosityLevel; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -121,9 +122,7 @@ public static function dataMergeInheritedPhpDocs(): array ]; } - /** - * @dataProvider dataMergeInheritedPhpDocs - */ + #[DataProvider('dataMergeInheritedPhpDocs')] public function testMergeInheritedPhpDocs( string $className, string $method, @@ -138,12 +137,9 @@ public function testMergeInheritedPhpDocs( $this->assertSame($expectedType, $throwsType->describe(VerbosityLevel::precise())); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/invalid-throws-property-hook.php'], [ [ 'PHPDoc tag @throws with type DateTimeImmutable is not subtype of Throwable', diff --git a/tests/PHPStan/Rules/PhpDoc/MethodConditionalReturnTypeRuleTest.php b/tests/PHPStan/Rules/PhpDoc/MethodConditionalReturnTypeRuleTest.php index ff465ea7e5..35ab5c2e4e 100644 --- a/tests/PHPStan/Rules/PhpDoc/MethodConditionalReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/MethodConditionalReturnTypeRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -96,12 +96,9 @@ public function testBug7310(): void $this->analyse([__DIR__ . '/data/bug-7310.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug11939(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-11939.php'], []); } diff --git a/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionClassRuleTest.php b/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionClassRuleTest.php index 9eeae901a9..8a9546216e 100644 --- a/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionClassRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionClassRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\ClassNameCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -33,12 +33,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/incompatible-require-extends.php'], [ [ 'PHPDoc tag @phpstan-require-extends cannot contain non-class type IncompatibleRequireExtends\SomeTrait.', diff --git a/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionTraitRuleTest.php b/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionTraitRuleTest.php index 9065530f89..e345685e67 100644 --- a/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionTraitRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionTraitRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\ClassNameCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -34,12 +34,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/incompatible-require-extends.php'], [ [ 'PHPDoc tag @phpstan-require-extends cannot contain final class IncompatibleRequireExtends\SomeFinalClass.', diff --git a/tests/PHPStan/Rules/PhpDoc/RequireImplementsDefinitionClassRuleTest.php b/tests/PHPStan/Rules/PhpDoc/RequireImplementsDefinitionClassRuleTest.php index fcba96a92e..807bbbc7d6 100644 --- a/tests/PHPStan/Rules/PhpDoc/RequireImplementsDefinitionClassRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/RequireImplementsDefinitionClassRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -17,12 +17,9 @@ protected function getRule(): Rule return new RequireImplementsDefinitionClassRule(); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/incompatible-require-implements.php'], [ [ 'PHPDoc tag @phpstan-require-implements is only valid on trait.', diff --git a/tests/PHPStan/Rules/PhpDoc/RequireImplementsDefinitionTraitRuleTest.php b/tests/PHPStan/Rules/PhpDoc/RequireImplementsDefinitionTraitRuleTest.php index 300947337a..1d0421388f 100644 --- a/tests/PHPStan/Rules/PhpDoc/RequireImplementsDefinitionTraitRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/RequireImplementsDefinitionTraitRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\ClassNameCheck; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -32,12 +32,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $expectedErrors = [ [ 'PHPDoc tag @phpstan-require-implements cannot contain non-interface type IncompatibleRequireImplements\SomeTrait.', diff --git a/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php b/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php index 219ebc1bc5..513c9118a7 100644 --- a/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php @@ -6,7 +6,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; use PHPStan\Type\FileTypeMapper; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -235,12 +236,9 @@ public function testBug11535(): void ]); } + #[RequiresPhp('>= 8.1')] public function testEnums(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('This test needs PHP 8.1'); - } - $this->analyse([__DIR__ . '/data/wrong-var-enum.php'], [ [ 'PHPDoc tag @var above an enum has no effect.', @@ -516,9 +514,7 @@ public static function dataReportWrongType(): iterable ]]; } - /** - * @dataProvider dataPermutateCheckTypeAgainst - */ + #[DataProvider('dataPermutateCheckTypeAgainst')] public function testEmptyArrayInitWithWiderPhpDoc(bool $checkTypeAgainstPhpDocType): void { $this->checkTypeAgainstPhpDocType = $checkTypeAgainstPhpDocType; @@ -537,9 +533,9 @@ public static function dataPermutateCheckTypeAgainst(): iterable } /** - * @dataProvider dataReportWrongType * @param list $expectedErrors */ + #[DataProvider('dataReportWrongType')] public function testReportWrongType( bool $checkTypeAgainstPhpDocType, bool $strictWideningCheck, diff --git a/tests/PHPStan/Rules/Playground/FunctionNeverRuleTest.php b/tests/PHPStan/Rules/Playground/FunctionNeverRuleTest.php index 2f580113f5..789c48ccfb 100644 --- a/tests/PHPStan/Rules/Playground/FunctionNeverRuleTest.php +++ b/tests/PHPStan/Rules/Playground/FunctionNeverRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -17,12 +17,9 @@ protected function getRule(): Rule return new FunctionNeverRule(new NeverRuleHelper()); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1 or greater.'); - } - $this->analyse([__DIR__ . '/data/function-never.php'], [ [ 'Function FunctionNever\doBar() always throws an exception, it should have return type "never".', diff --git a/tests/PHPStan/Rules/Playground/MethodNeverRuleTest.php b/tests/PHPStan/Rules/Playground/MethodNeverRuleTest.php index 83e315479d..35b3d20463 100644 --- a/tests/PHPStan/Rules/Playground/MethodNeverRuleTest.php +++ b/tests/PHPStan/Rules/Playground/MethodNeverRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -17,12 +17,9 @@ protected function getRule(): Rule return new MethodNeverRule(new NeverRuleHelper()); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1 or greater.'); - } - $this->analyse([__DIR__ . '/data/method-never.php'], [ [ 'Method MethodNever\Foo::doBar() always throws an exception, it should have return type "never".', diff --git a/tests/PHPStan/Rules/Playground/PromoteParameterRuleWithOriginalRuleTest.php b/tests/PHPStan/Rules/Playground/PromoteParameterRuleWithOriginalRuleTest.php index 0e06c3e223..4495def574 100644 --- a/tests/PHPStan/Rules/Playground/PromoteParameterRuleWithOriginalRuleTest.php +++ b/tests/PHPStan/Rules/Playground/PromoteParameterRuleWithOriginalRuleTest.php @@ -11,7 +11,7 @@ use PHPStan\Rules\Methods\OverridingMethodRule; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase> @@ -38,12 +38,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.3')] public function testRule(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->analyse([__DIR__ . '/data/promote-missing-override.php'], [ [ 'Method PromoteMissingOverride\Bar::doFoo() overrides method PromoteMissingOverride\Foo::doFoo() but is missing the #[\Override] attribute.', diff --git a/tests/PHPStan/Rules/Properties/AccessPropertiesInAssignRuleTest.php b/tests/PHPStan/Rules/Properties/AccessPropertiesInAssignRuleTest.php index 55f6f3bb11..c89cf2867b 100644 --- a/tests/PHPStan/Rules/Properties/AccessPropertiesInAssignRuleTest.php +++ b/tests/PHPStan/Rules/Properties/AccessPropertiesInAssignRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -122,12 +123,9 @@ public function testBug10477(): void $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-10477.php'], []); } + #[RequiresPhp('>= 8.4')] public function testAsymmetricVisibility(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/write-asymmetric-visibility.php'], [ [ 'Assign to private(set) property $this(WriteAsymmetricVisibility\Bar)::$a.', diff --git a/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php index d8e9f33ac3..5d3697767d 100644 --- a/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php @@ -6,6 +6,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_merge; use const PHP_VERSION_ID; @@ -536,11 +538,9 @@ public function testBug4808(): void $this->analyse([__DIR__ . '/data/bug-4808.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug5868(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0'); - } $this->checkThisOnly = false; $this->checkUnionTypes = true; $this->checkDynamicProperties = false; @@ -564,12 +564,9 @@ public function testBug5868(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug6385(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->checkThisOnly = false; $this->checkUnionTypes = true; $this->checkDynamicProperties = false; @@ -589,11 +586,9 @@ public function testBug6385(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug6566(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } $this->checkThisOnly = false; $this->checkUnionTypes = true; $this->checkDynamicProperties = false; @@ -771,9 +766,9 @@ public static function dataDynamicProperties(): array } /** - * @dataProvider dataDynamicProperties * @param list $errors */ + #[DataProvider('dataDynamicProperties')] public function testDynamicProperties(bool $checkDynamicProperties, array $errors): void { $this->checkThisOnly = false; @@ -815,9 +810,7 @@ public static function dataTrueAndFalse(): array ]; } - /** - * @dataProvider dataTrueAndFalse - */ + #[DataProvider('dataTrueAndFalse')] public function testPhp82AndDynamicProperties(bool $b): void { $errors = []; @@ -868,9 +861,7 @@ public function testPhp82AndDynamicProperties(bool $b): void $this->analyse([__DIR__ . '/data/php-82-dynamic-properties.php'], $errors); } - /** - * @dataProvider dataTrueAndFalse - */ + #[DataProvider('dataTrueAndFalse')] public function testPhp82AndDynamicPropertiesAllow(bool $b): void { $errors = []; @@ -949,12 +940,9 @@ public function testConflictingAnnotationProperty(): void $this->analyse([__DIR__ . '/data/conflicting-annotation-property.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug8536(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->checkThisOnly = false; $this->checkUnionTypes = true; $this->checkDynamicProperties = true; @@ -985,12 +973,9 @@ public function testBug8629(): void $this->analyse([__DIR__ . '/data/bug-8629.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug9694(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkThisOnly = false; $this->checkUnionTypes = true; $this->checkDynamicProperties = true; @@ -1005,24 +990,18 @@ public function testTraitMixin(): void $this->analyse([__DIR__ . '/data/trait-mixin.php'], []); } + #[RequiresPhp('>= 8.4')] public function testAsymmetricVisibility(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->checkThisOnly = false; $this->checkUnionTypes = true; $this->checkDynamicProperties = true; $this->analyse([__DIR__ . '/data/read-asymmetric-visibility.php'], []); } + #[RequiresPhp('>= 8.2')] public function testNewIsAlwaysFinalClass(): void { - if (PHP_VERSION_ID < 80200) { - $this->markTestSkipped('Test requires PHP 8.2.'); - } - $this->checkThisOnly = false; $this->checkUnionTypes = true; $this->checkDynamicProperties = false; diff --git a/tests/PHPStan/Rules/Properties/ExistingClassesInPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/ExistingClassesInPropertiesRuleTest.php index 4c1b97c45a..ac30206c91 100644 --- a/tests/PHPStan/Rules/Properties/ExistingClassesInPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/ExistingClassesInPropertiesRuleTest.php @@ -9,6 +9,7 @@ use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use const PHP_VERSION_ID; /** @@ -167,9 +168,9 @@ public static function dataIntersectionTypes(): array } /** - * @dataProvider dataIntersectionTypes * @param list $errors */ + #[DataProvider('dataIntersectionTypes')] public function testIntersectionTypes(int $phpVersion, array $errors): void { $this->phpVersion = $phpVersion; diff --git a/tests/PHPStan/Rules/Properties/ExistingClassesInPropertyHookTypehintsRuleTest.php b/tests/PHPStan/Rules/Properties/ExistingClassesInPropertyHookTypehintsRuleTest.php index da7c43d985..05610e0482 100644 --- a/tests/PHPStan/Rules/Properties/ExistingClassesInPropertyHookTypehintsRuleTest.php +++ b/tests/PHPStan/Rules/Properties/ExistingClassesInPropertyHookTypehintsRuleTest.php @@ -10,6 +10,7 @@ use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -38,12 +39,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.4')] public function testRule(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/existing-classes-property-hooks.php'], [ [ 'Parameter $v of set hook for property ExistingClassesPropertyHooks\Foo::$i has invalid type ExistingClassesPropertyHooks\Nonexistent.', diff --git a/tests/PHPStan/Rules/Properties/GetNonVirtualPropertyHookReadRuleTest.php b/tests/PHPStan/Rules/Properties/GetNonVirtualPropertyHookReadRuleTest.php index 64745b60d9..e00ba2dd3f 100644 --- a/tests/PHPStan/Rules/Properties/GetNonVirtualPropertyHookReadRuleTest.php +++ b/tests/PHPStan/Rules/Properties/GetNonVirtualPropertyHookReadRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -17,12 +17,9 @@ protected function getRule(): Rule return new GetNonVirtualPropertyHookReadRule(); } + #[RequiresPhp('>= 8.4')] public function testRule(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/get-non-virtual-property-hook-read.php'], [ [ 'Get hook for non-virtual property GetNonVirtualPropertyHookRead\Foo::$k does not read its value.', @@ -35,12 +32,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.4')] public function testAbstractProperty(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/get-abstract-property-hook-read.php'], []); } diff --git a/tests/PHPStan/Rules/Properties/MissingReadOnlyByPhpDocPropertyAssignRuleTest.php b/tests/PHPStan/Rules/Properties/MissingReadOnlyByPhpDocPropertyAssignRuleTest.php index a72e7d23f2..b503c69e45 100644 --- a/tests/PHPStan/Rules/Properties/MissingReadOnlyByPhpDocPropertyAssignRuleTest.php +++ b/tests/PHPStan/Rules/Properties/MissingReadOnlyByPhpDocPropertyAssignRuleTest.php @@ -6,8 +6,8 @@ use PHPStan\Reflection\PropertyReflection; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function in_array; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -143,12 +143,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testRuleIgnoresNativeReadonly(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/missing-readonly-property-assign-phpdoc-and-native.php'], []); } diff --git a/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php b/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php index f389c3f628..6d1772cc75 100644 --- a/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php +++ b/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php @@ -6,9 +6,9 @@ use PHPStan\Reflection\PropertyReflection; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function in_array; use function strpos; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -87,12 +87,9 @@ public function isInitialized(PropertyReflection $property, string $propertyName ]; } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/missing-readonly-property-assign.php'], [ [ 'Class MissingReadOnlyPropertyAssign\Foo has an uninitialized readonly property $unassigned. Assign it in the constructor.', @@ -161,57 +158,39 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug7119(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-7119.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug7314(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-7314.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug8412(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-8412.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug8958(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-8958.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug8563(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-8563.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug6402(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-6402.php'], [ [ 'Access to an uninitialized readonly property Bug6402\SomeModel2::$views.', @@ -220,21 +199,15 @@ public function testBug6402(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug7198(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-7198.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug7649(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-7649.php'], [ [ 'Class Bug7649\Foo has an uninitialized readonly property $bar. Assign it in the constructor.', @@ -243,12 +216,9 @@ public function testBug7649(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug9577(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/../Classes/data/bug-9577.php'], [ [ 'Class Bug9577\SpecializedException2 has an uninitialized readonly property $message. Assign it in the constructor.', @@ -257,12 +227,9 @@ public function testBug9577(): void ]); } + #[RequiresPhp('>= 8.3')] public function testAnonymousReadonlyClass(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->analyse([__DIR__ . '/data/missing-readonly-anonymous-class-property-assign.php'], [ [ 'Class class@anonymous/tests/PHPStan/Rules/Properties/data/missing-readonly-anonymous-class-property-assign.php:10 has an uninitialized readonly property $foo. Assign it in the constructor.', @@ -271,12 +238,9 @@ public function testAnonymousReadonlyClass(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug10523(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-10523.php'], [ [ 'Readonly property Bug10523\MultipleWrites::$userAccount is already assigned.', @@ -285,21 +249,15 @@ public function testBug10523(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug10822(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-10822.php'], []); } + #[RequiresPhp('>= 8.1')] public function testRedeclaredReadonlyProperties(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/redeclare-readonly-property.php'], [ [ 'Readonly property RedeclareReadonlyProperty\B1::$myProp is already assigned.', @@ -332,12 +290,9 @@ public function testRedeclaredReadonlyProperties(): void ]); } + #[RequiresPhp('>= 8.2')] public function testRedeclaredPropertiesOfReadonlyClass(): void { - if (PHP_VERSION_ID < 80200) { - $this->markTestSkipped('Test requires PHP 8.2.'); - } - $this->analyse([__DIR__ . '/data/redeclare-property-of-readonly-class.php'], [ [ 'Readonly property RedeclarePropertyOfReadonlyClass\B1::$promotedProp is already assigned.', @@ -346,12 +301,9 @@ public function testRedeclaredPropertiesOfReadonlyClass(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug8101(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-8101.php'], [ [ 'Readonly property Bug8101\B::$myProp is already assigned.', @@ -360,12 +312,9 @@ public function testBug8101(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug9863(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9863.php'], [ [ 'Readonly property Bug9863\ReadonlyChildWithoutIsset::$foo is already assigned.', @@ -382,32 +331,23 @@ public function testBug9863(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug10048(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->shouldNarrowMethodScopeFromConstructor = true; $this->analyse([__DIR__ . '/data/bug-10048.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug11828(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->shouldNarrowMethodScopeFromConstructor = true; $this->analyse([__DIR__ . '/data/bug-11828.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9864(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-9864.php'], []); } diff --git a/tests/PHPStan/Rules/Properties/NullsafePropertyFetchRuleTest.php b/tests/PHPStan/Rules/Properties/NullsafePropertyFetchRuleTest.php index 07300834bf..259f973c22 100644 --- a/tests/PHPStan/Rules/Properties/NullsafePropertyFetchRuleTest.php +++ b/tests/PHPStan/Rules/Properties/NullsafePropertyFetchRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -32,30 +32,21 @@ public function testBug6020(): void $this->analyse([__DIR__ . '/data/bug-6020.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug7109(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/bug-7109.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug5172(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-5172.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug7980(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/../../Analyser/data/bug-7980.php'], []); } @@ -64,21 +55,15 @@ public function testBug8517(): void $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-8517.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug9105(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-9105.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug6922(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-6922.php'], []); } diff --git a/tests/PHPStan/Rules/Properties/OverridingPropertyRuleTest.php b/tests/PHPStan/Rules/Properties/OverridingPropertyRuleTest.php index 5aec8932fb..1384576b1d 100644 --- a/tests/PHPStan/Rules/Properties/OverridingPropertyRuleTest.php +++ b/tests/PHPStan/Rules/Properties/OverridingPropertyRuleTest.php @@ -5,8 +5,9 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function sprintf; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -156,9 +157,9 @@ public static function dataRulePHPDocTypes(): array } /** - * @dataProvider dataRulePHPDocTypes * @param list $errors */ + #[DataProvider('dataRulePHPDocTypes')] public function testRulePHPDocTypes(bool $reportMaybes, array $errors): void { $this->reportMaybes = $reportMaybes; @@ -177,12 +178,9 @@ public function testBug7692(): void $this->analyse([__DIR__ . '/data/bug-7692.php'], []); } + #[RequiresPhp('>= 8.4')] public function testFinal(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->reportMaybes = true; $this->analyse([__DIR__ . '/data/overriding-final-property.php'], [ [ @@ -212,12 +210,9 @@ public function testFinal(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPropertyPrototypeFromInterface(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->reportMaybes = true; $this->analyse([__DIR__ . '/data/property-prototype-from-interface.php'], [ [ @@ -239,12 +234,9 @@ public function testPropertyPrototypeFromInterface(): void ]); } + #[RequiresPhp('>= 8.4')] public function testBug12466(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $tip = sprintf( "You can fix 3rd party PHPDoc types with stub files:\n %s", 'https://phpstan.org/user-guide/stub-files', @@ -273,12 +265,9 @@ public function testBug12466(): void ]); } + #[RequiresPhp('>= 8.4')] public function testBug12586(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->reportMaybes = true; $this->analyse([__DIR__ . '/data/bug-12586.php'], [ [ diff --git a/tests/PHPStan/Rules/Properties/PropertiesInInterfaceRuleTest.php b/tests/PHPStan/Rules/Properties/PropertiesInInterfaceRuleTest.php index 5cfb5e7b58..3edbe05c09 100644 --- a/tests/PHPStan/Rules/Properties/PropertiesInInterfaceRuleTest.php +++ b/tests/PHPStan/Rules/Properties/PropertiesInInterfaceRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -18,15 +19,13 @@ protected function getRule(): Rule return new PropertiesInInterfaceRule(new PhpVersion(PHP_VERSION_ID)); } + #[RequiresPhp('< 8.4')] public function testPhp83AndPropertiesInInterface(): void { - if (PHP_VERSION_ID >= 80400) { - $this->markTestSkipped('Test requires PHP 8.3 or earlier.'); - } + // @phpstan-ignore phpstan.skipTestsRequiresPhp if (PHP_VERSION_ID < 80000) { $this->markTestSkipped('Property hooks cause syntax error on PHP 7.4'); } - $this->analyse([__DIR__ . '/data/properties-in-interface.php'], [ [ 'Interfaces can include properties only on PHP 8.4 and later.', @@ -47,15 +46,13 @@ public function testPhp83AndPropertiesInInterface(): void ]); } + #[RequiresPhp('< 8.4')] public function testPhp83AndPropertyHooksInInterface(): void { - if (PHP_VERSION_ID >= 80400) { - $this->markTestSkipped('Test requires PHP 8.3 or earlier.'); - } + // @phpstan-ignore phpstan.skipTestsRequiresPhp if (PHP_VERSION_ID < 80000) { $this->markTestSkipped('Property hooks cause syntax error on PHP 7.4'); } - $this->analyse([__DIR__ . '/data/property-hooks-in-interface.php'], [ [ 'Interfaces can include properties only on PHP 8.4 and later.', @@ -68,12 +65,9 @@ public function testPhp83AndPropertyHooksInInterface(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndPropertiesInInterface(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/properties-in-interface.php'], [ [ 'Interfaces can only include hooked properties.', @@ -90,12 +84,9 @@ public function testPhp84AndPropertiesInInterface(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndNonPublicPropertyHooksInInterface(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/property-hooks-visibility-in-interface.php'], [ [ 'Interfaces cannot include non-public properties.', @@ -108,12 +99,9 @@ public function testPhp84AndNonPublicPropertyHooksInInterface(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndPropertyHooksWithBodiesInInterface(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/property-hooks-bodies-in-interface.php'], [ [ 'Interfaces cannot include property hooks with bodies.', @@ -126,12 +114,9 @@ public function testPhp84AndPropertyHooksWithBodiesInInterface(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndReadonlyPropertyHooksInInterface(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/readonly-property-hooks-in-interface.php'], [ [ 'Interfaces cannot include readonly hooked properties.', @@ -148,12 +133,9 @@ public function testPhp84AndReadonlyPropertyHooksInInterface(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndFinalPropertyHooksInInterface(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/final-property-hooks-in-interface.php'], [ [ 'Interfaces cannot include final properties.', @@ -178,12 +160,9 @@ public function testPhp84AndFinalPropertyHooksInInterface(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndExplicitAbstractProperty(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/property-in-interface-explicit-abstract.php'], [ [ 'Property in interface cannot be explicitly abstract.', @@ -192,12 +171,9 @@ public function testPhp84AndExplicitAbstractProperty(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndStaticHookedPropertyInInterface(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/static-hooked-property-in-interface.php'], [ [ 'Hooked properties cannot be static.', diff --git a/tests/PHPStan/Rules/Properties/PropertyAssignRefRuleTest.php b/tests/PHPStan/Rules/Properties/PropertyAssignRefRuleTest.php index 3d78abbee9..2759afcfed 100644 --- a/tests/PHPStan/Rules/Properties/PropertyAssignRefRuleTest.php +++ b/tests/PHPStan/Rules/Properties/PropertyAssignRefRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -18,12 +19,9 @@ protected function getRule(): Rule return new PropertyAssignRefRule(new PhpVersion(PHP_VERSION_ID), new PropertyReflectionFinder()); } + #[RequiresPhp('>= 8.4')] public function testRule(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/property-assign-ref.php'], [ [ 'Property PropertyAssignRef\Foo::$foo with private visibility is assigned by reference.', @@ -44,12 +42,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.4')] public function testAsymmetricVisibility(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/property-assign-ref-asymmetric.php'], [ [ 'Property PropertyAssignRefAsymmetric\Foo::$a with private(set) visibility is assigned by reference.', diff --git a/tests/PHPStan/Rules/Properties/PropertyHookAttributesRuleTest.php b/tests/PHPStan/Rules/Properties/PropertyHookAttributesRuleTest.php index 382f43f18d..ef9b16df15 100644 --- a/tests/PHPStan/Rules/Properties/PropertyHookAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/PropertyHookAttributesRuleTest.php @@ -12,7 +12,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -47,12 +47,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.4')] public function testRule(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/property-hook-attributes.php'], [ [ 'Attribute class PropertyHookAttributes\Foo does not have the method target.', diff --git a/tests/PHPStan/Rules/Properties/PropertyInClassRuleTest.php b/tests/PHPStan/Rules/Properties/PropertyInClassRuleTest.php index e0b65f8bd1..d04cdb6667 100644 --- a/tests/PHPStan/Rules/Properties/PropertyInClassRuleTest.php +++ b/tests/PHPStan/Rules/Properties/PropertyInClassRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -18,11 +19,10 @@ protected function getRule(): Rule return new PropertyInClassRule(new PhpVersion(PHP_VERSION_ID)); } + #[RequiresPhp('< 8.4')] public function testPhpLessThan84AndHookedPropertiesInClass(): void { - if (PHP_VERSION_ID >= 80400) { - $this->markTestSkipped('Test requires PHP 8.3 or earlier.'); - } + // @phpstan-ignore phpstan.skipTestsRequiresPhp if (PHP_VERSION_ID < 80000) { $this->markTestSkipped('Property hooks cause syntax error on PHP 7.4'); } @@ -35,10 +35,12 @@ public function testPhpLessThan84AndHookedPropertiesInClass(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndHookedPropertiesWithoutBodiesInClass(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); + // @phpstan-ignore phpstan.skipTestsRequiresPhp + if (PHP_VERSION_ID < 80000) { + $this->markTestSkipped('Property hooks cause syntax error on PHP 7.4'); } $this->analyse([__DIR__ . '/data/hooked-properties-without-bodies-in-class.php'], [ @@ -57,12 +59,9 @@ public function testPhp84AndHookedPropertiesWithoutBodiesInClass(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndNonAbstractHookedPropertiesInClass(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/non-abstract-hooked-properties-in-class.php'], [ [ 'Non-abstract properties cannot include hooks without bodies.', @@ -75,12 +74,9 @@ public function testPhp84AndNonAbstractHookedPropertiesInClass(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndAbstractHookedPropertiesInClass(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/abstract-hooked-properties-in-class.php'], [ [ 'Non-abstract classes cannot include abstract properties.', @@ -93,12 +89,9 @@ public function testPhp84AndAbstractHookedPropertiesInClass(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndNonAbstractHookedPropertiesInAbstractClass(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/non-abstract-hooked-properties-in-abstract-class.php'], [ [ 'Non-abstract properties cannot include hooks without bodies.', @@ -115,12 +108,9 @@ public function testPhp84AndNonAbstractHookedPropertiesInAbstractClass(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndAbstractNonHookedPropertiesInAbstractClass(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/abstract-non-hooked-properties-in-abstract-class.php'], [ [ 'Only hooked properties can be declared abstract.', @@ -133,12 +123,9 @@ public function testPhp84AndAbstractNonHookedPropertiesInAbstractClass(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndAbstractHookedPropertiesWithBodies(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/abstract-hooked-properties-with-bodies.php'], [ [ 'Abstract properties must specify at least one abstract hook.', @@ -151,12 +138,9 @@ public function testPhp84AndAbstractHookedPropertiesWithBodies(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndReadonlyHookedProperties(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/readonly-property-hooks.php'], [ [ 'Hooked properties cannot be readonly.', @@ -181,12 +165,9 @@ public function testPhp84AndReadonlyHookedProperties(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndVirtualHookedProperties(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/virtual-hooked-properties.php'], [ [ 'Virtual hooked properties cannot have a default value.', @@ -195,12 +176,9 @@ public function testPhp84AndVirtualHookedProperties(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndStaticHookedProperties(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/static-hooked-properties.php'], [ [ 'Hooked properties cannot be static.', @@ -213,12 +191,9 @@ public function testPhp84AndStaticHookedProperties(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndPrivateFinalHookedProperties(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/private-final-property-hooks.php'], [ [ 'Property cannot be both final and private.', @@ -231,12 +206,9 @@ public function testPhp84AndPrivateFinalHookedProperties(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndAbstractFinalHookedProperties(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/abstract-final-property-hook.php'], [ [ 'Property cannot be both abstract and final.', @@ -245,12 +217,9 @@ public function testPhp84AndAbstractFinalHookedProperties(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndAbstractPrivateHookedProperties(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/abstract-private-property-hook.php'], [ [ 'Property cannot be both abstract and private.', @@ -259,12 +228,9 @@ public function testPhp84AndAbstractPrivateHookedProperties(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84AndAbstractFinalHookedPropertiesParseError(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - // errors when parsing with php-parser, see https://github.com/nikic/PHP-Parser/issues/1071 $this->analyse([__DIR__ . '/data/abstract-final-property-hook-parse-error.php'], [ [ @@ -274,12 +240,9 @@ public function testPhp84AndAbstractFinalHookedPropertiesParseError(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84FinalProperties(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/final-properties.php'], [ [ 'Property cannot be both final and private.', @@ -288,12 +251,9 @@ public function testPhp84FinalProperties(): void ]); } + #[RequiresPhp('< 8.4')] public function testBeforePhp84FinalProperties(): void { - if (PHP_VERSION_ID >= 80400) { - $this->markTestSkipped('Test requires PHP 8.3 or earlier.'); - } - $this->analyse([__DIR__ . '/data/final-properties.php'], [ [ 'Final properties are supported only on PHP 8.4 and later.', @@ -310,12 +270,9 @@ public function testBeforePhp84FinalProperties(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPhp84FinalPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/final-property-hooks.php'], [ [ 'Cannot use the final modifier on an abstract class member on line 19', diff --git a/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyAssignRefRuleTest.php b/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyAssignRefRuleTest.php index d000d4f3f3..5a228e1bb0 100644 --- a/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyAssignRefRuleTest.php +++ b/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyAssignRefRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -59,12 +59,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testRuleIgnoresNativeReadonly(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/readonly-assign-ref-phpdoc-and-native.php'], []); } diff --git a/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyAssignRuleTest.php b/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyAssignRuleTest.php index 0aecf4c09c..adbd30eb43 100644 --- a/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyAssignRuleTest.php +++ b/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyAssignRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Reflection\ConstructorsHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -132,21 +132,15 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testRuleIgnoresNativeReadonly(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/readonly-assign-phpdoc-and-native.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug7361(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-7361.php'], [ [ '@readonly property Bug7361\Example::$foo is assigned outside of the constructor.', @@ -155,21 +149,15 @@ public function testBug7361(): void ]); } + #[RequiresPhp('>= 8.1')] public function testFeature7648(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/feature-7648.php'], []); } + #[RequiresPhp('>= 7.4')] public function testFeature11775(): void { - if (PHP_VERSION_ID < 70400) { - $this->markTestSkipped('Test requires PHP 7.4.'); - } - $this->analyse([__DIR__ . '/data/feature-11775.php'], [ [ '@readonly property Feature11775\FooImmutable::$i is assigned outside of the constructor.', @@ -182,12 +170,9 @@ public function testFeature11775(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/property-hooks-readonly-by-phpdoc-assign.php'], [ [ '@readonly property PropertyHooksReadonlyByPhpDocAssign\Foo::$i is assigned outside of the constructor.', diff --git a/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyRuleTest.php b/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyRuleTest.php index c2dce590b6..13d3d988aa 100644 --- a/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyRuleTest.php +++ b/tests/PHPStan/Rules/Properties/ReadOnlyByPhpDocPropertyRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -17,12 +17,9 @@ protected function getRule(): Rule return new ReadOnlyByPhpDocPropertyRule(); } + #[RequiresPhp('>= 8.0')] public function testRule(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/read-only-property-phpdoc.php'], [ [ '@readonly property cannot have a default value.', @@ -43,21 +40,15 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testRuleIgnoresNativeReadonly(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/read-only-property-phpdoc-and-native.php'], []); } + #[RequiresPhp('>= 8.0')] public function testRuleAllowedPrivateMutation(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/read-only-property-phpdoc-allowed-private-mutation.php'], [ [ '@readonly property cannot have a default value.', diff --git a/tests/PHPStan/Rules/Properties/ReadOnlyPropertyAssignRefRuleTest.php b/tests/PHPStan/Rules/Properties/ReadOnlyPropertyAssignRefRuleTest.php index e8acef73f8..4e0d4b4293 100644 --- a/tests/PHPStan/Rules/Properties/ReadOnlyPropertyAssignRefRuleTest.php +++ b/tests/PHPStan/Rules/Properties/ReadOnlyPropertyAssignRefRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -17,12 +18,9 @@ protected function getRule(): Rule return new ReadOnlyPropertyAssignRefRule(new PropertyReflectionFinder()); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $errors = [ [ 'Readonly property ReadOnlyPropertyAssignRef\Foo::$foo is assigned by reference.', diff --git a/tests/PHPStan/Rules/Properties/ReadOnlyPropertyAssignRuleTest.php b/tests/PHPStan/Rules/Properties/ReadOnlyPropertyAssignRuleTest.php index d54ae3a02f..f5a471f6eb 100644 --- a/tests/PHPStan/Rules/Properties/ReadOnlyPropertyAssignRuleTest.php +++ b/tests/PHPStan/Rules/Properties/ReadOnlyPropertyAssignRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Reflection\ConstructorsHelper; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_merge; use const PHP_VERSION_ID; @@ -27,12 +28,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1'); - } - $errors = [ [ 'Readonly property ReadonlyPropertyAssign\Foo::$foo is assigned outside of the constructor.', @@ -131,12 +129,9 @@ public function testRule(): void $this->analyse([__DIR__ . '/data/readonly-assign.php'], $errors); } + #[RequiresPhp('>= 8.1')] public function testFeature7648(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/feature-7648.php'], [ [ 'Readonly property Feature7648\Request::$offset is assigned outside of the constructor.', @@ -145,12 +140,9 @@ public function testFeature7648(): void ]); } + #[RequiresPhp('>= 8.1')] public function testReadOnlyClasses(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/readonly-class-assign.php'], [ [ 'Readonly property ReadonlyClassPropertyAssign\Foo::$foo is assigned outside of the constructor.', @@ -159,12 +151,9 @@ public function testReadOnlyClasses(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug6773(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-6773.php'], [ [ 'Readonly property Bug6773\Repository::$data is assigned outside of the constructor.', @@ -173,21 +162,15 @@ public function testBug6773(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug8929(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-8929.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug12537(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-12537.php'], []); } diff --git a/tests/PHPStan/Rules/Properties/ReadOnlyPropertyRuleTest.php b/tests/PHPStan/Rules/Properties/ReadOnlyPropertyRuleTest.php index fd218d8ea3..1f51f7ad26 100644 --- a/tests/PHPStan/Rules/Properties/ReadOnlyPropertyRuleTest.php +++ b/tests/PHPStan/Rules/Properties/ReadOnlyPropertyRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * @extends RuleTestCase @@ -80,9 +81,9 @@ public static function dataRule(): array } /** - * @dataProvider dataRule * @param list $errors */ + #[DataProvider('dataRule')] public function testRule(int $phpVersionId, array $errors): void { $this->phpVersionId = $phpVersionId; @@ -90,9 +91,9 @@ public function testRule(int $phpVersionId, array $errors): void } /** - * @dataProvider dataRule * @param list $errors */ + #[DataProvider('dataRule')] public function testRuleReadonlyClass(int $phpVersionId, array $errors): void { $this->phpVersionId = $phpVersionId; diff --git a/tests/PHPStan/Rules/Properties/ReadingWriteOnlyPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/ReadingWriteOnlyPropertiesRuleTest.php index e06990b5a7..1a12b6047c 100644 --- a/tests/PHPStan/Rules/Properties/ReadingWriteOnlyPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/ReadingWriteOnlyPropertiesRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -89,12 +89,9 @@ public function testConflictingAnnotationProperty(): void $this->analyse([__DIR__ . '/data/conflicting-annotation-property.php'], []); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->checkThisOnly = false; $this->analyse([__DIR__ . '/data/reading-write-only-hooked-properties.php'], [ [ diff --git a/tests/PHPStan/Rules/Properties/SetNonVirtualPropertyHookAssignRuleTest.php b/tests/PHPStan/Rules/Properties/SetNonVirtualPropertyHookAssignRuleTest.php index bdfcaf5f27..e4c9a0bb7f 100644 --- a/tests/PHPStan/Rules/Properties/SetNonVirtualPropertyHookAssignRuleTest.php +++ b/tests/PHPStan/Rules/Properties/SetNonVirtualPropertyHookAssignRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -17,12 +17,9 @@ protected function getRule(): Rule return new SetNonVirtualPropertyHookAssignRule(); } + #[RequiresPhp('>= 8.4')] public function testRule(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/set-non-virtual-property-hook-assign.php'], [ [ 'Set hook for non-virtual property SetNonVirtualPropertyHookAssign\Foo::$k does not assign value to it.', diff --git a/tests/PHPStan/Rules/Properties/SetPropertyHookParameterRuleTest.php b/tests/PHPStan/Rules/Properties/SetPropertyHookParameterRuleTest.php index 0b879f0ad5..588845b5a1 100644 --- a/tests/PHPStan/Rules/Properties/SetPropertyHookParameterRuleTest.php +++ b/tests/PHPStan/Rules/Properties/SetPropertyHookParameterRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\MissingTypehintCheck; use PHPStan\Rules\Rule as TRule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -18,12 +18,9 @@ protected function getRule(): TRule return new SetPropertyHookParameterRule(new MissingTypehintCheck(true, []), true, true); } + #[RequiresPhp('>= 8.4')] public function testRule(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/set-property-hook-parameter.php'], [ [ 'Parameter $v of set hook has a native type but the property SetPropertyHookParameter\Bar::$a does not.', diff --git a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php index fcd1599c88..7964f5b3ee 100644 --- a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -633,12 +633,9 @@ public function testBug10686(): void $this->analyse([__DIR__ . '/data/bug-10686.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug11275(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = true; $this->analyse([__DIR__ . '/data/bug-11275.php'], [ [ @@ -698,22 +695,16 @@ public function testBug6571(): void $this->analyse([__DIR__ . '/data/bug-6571.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug12565(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->checkExplicitMixed = true; $this->analyse([__DIR__ . '/data/bug-12565.php'], []); } + #[RequiresPhp('>= 8.4')] public function testShortBodySetHook(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->checkExplicitMixed = true; $this->analyse([__DIR__ . '/data/short-set-property-hook-assign.php'], [ [ @@ -742,12 +733,9 @@ public function testShortBodySetHook(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/assign-hooked-properties.php'], [ [ 'Property AssignHookedProperties\Foo::$i (int) does not accept array|int.', diff --git a/tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php b/tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php index 22c15b707b..940dc461a3 100644 --- a/tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php +++ b/tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php @@ -6,8 +6,8 @@ use PHPStan\Reflection\PropertyReflection; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function strpos; -use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -217,21 +217,15 @@ public function testRedeclareReadonlyProperties(): void ]); } + #[RequiresPhp('>= 8.4')] public function testBug12336(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/bug-12336.php'], []); } + #[RequiresPhp('>= 8.4')] public function testBug12547(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->analyse([__DIR__ . '/data/bug-12547.php'], []); } diff --git a/tests/PHPStan/Rules/Properties/WritingToReadOnlyPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/WritingToReadOnlyPropertiesRuleTest.php index 39e81fe08a..1dd3766d94 100644 --- a/tests/PHPStan/Rules/Properties/WritingToReadOnlyPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/WritingToReadOnlyPropertiesRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -88,12 +88,9 @@ public function testConflictingAnnotationProperty(): void ]); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->checkThisOnly = false; $this->analyse([__DIR__ . '/data/writing-to-read-only-hooked-properties.php'], [ [ @@ -107,12 +104,9 @@ public function testPropertyHooks(): void ]); } + #[RequiresPhp('>= 8.4')] public function testBug12553(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->checkThisOnly = false; $this->analyse([__DIR__ . '/../Variables/data/bug-12553.php'], []); } diff --git a/tests/PHPStan/Rules/Pure/PureFunctionRuleTest.php b/tests/PHPStan/Rules/Pure/PureFunctionRuleTest.php index 9be4df6153..44e326a0d6 100644 --- a/tests/PHPStan/Rules/Pure/PureFunctionRuleTest.php +++ b/tests/PHPStan/Rules/Pure/PureFunctionRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -107,12 +107,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testFirstClassCallable(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/first-class-callable-pure-function.php'], [ [ 'Impure call to method FirstClassCallablePureFunction\Foo::impureFunction() in pure function FirstClassCallablePureFunction\testThese().', diff --git a/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php b/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php index fc573151e5..b5a44ee822 100644 --- a/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php +++ b/tests/PHPStan/Rules/Pure/PureMethodRuleTest.php @@ -4,7 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -151,12 +152,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.0')] public function testPureConstructor(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/pure-constructor.php'], [ [ @@ -189,9 +187,7 @@ public function testImpureAssignRef(): void ]); } - /** - * @dataProvider dataBug11207 - */ + #[DataProvider('dataBug11207')] public function testBug11207(bool $treatPhpDocTypesAsCertain): void { $this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain; diff --git a/tests/PHPStan/Rules/Regexp/RegularExpressionPatternRuleTest.php b/tests/PHPStan/Rules/Regexp/RegularExpressionPatternRuleTest.php index 6c94e6d96e..00f0db3ce3 100644 --- a/tests/PHPStan/Rules/Regexp/RegularExpressionPatternRuleTest.php +++ b/tests/PHPStan/Rules/Regexp/RegularExpressionPatternRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; use PHPStan\Type\Regex\RegexExpressionHelper; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; use const PHP_VERSION_ID; @@ -152,8 +153,8 @@ public function testValidRegexPattern(): void /** * @param list $errors - * @dataProvider dataArrayShapePatterns */ + #[DataProvider('dataArrayShapePatterns')] public function testArrayShapePatterns(string $file, array $errors): void { $this->analyse( diff --git a/tests/PHPStan/Rules/Regexp/RegularExpressionQuotingRuleTest.php b/tests/PHPStan/Rules/Regexp/RegularExpressionQuotingRuleTest.php index a74a1a34e4..5616a2bfc4 100644 --- a/tests/PHPStan/Rules/Regexp/RegularExpressionQuotingRuleTest.php +++ b/tests/PHPStan/Rules/Regexp/RegularExpressionQuotingRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; use PHPStan\Type\Regex\RegexExpressionHelper; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -74,12 +74,9 @@ public function testRule(): void ); } + #[RequiresPhp('>= 8.0')] public function testRulePhp8(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse( [__DIR__ . '/data/preg-quote-php8.php'], [ diff --git a/tests/PHPStan/Rules/RestrictedUsage/RestrictedFunctionCallableUsageRuleTest.php b/tests/PHPStan/Rules/RestrictedUsage/RestrictedFunctionCallableUsageRuleTest.php index 49a23ac859..1a72aef601 100644 --- a/tests/PHPStan/Rules/RestrictedUsage/RestrictedFunctionCallableUsageRuleTest.php +++ b/tests/PHPStan/Rules/RestrictedUsage/RestrictedFunctionCallableUsageRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -20,12 +20,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/restricted-function-callable.php'], [ [ 'Cannot call doFoo', diff --git a/tests/PHPStan/Rules/RestrictedUsage/RestrictedMethodCallableUsageRuleTest.php b/tests/PHPStan/Rules/RestrictedUsage/RestrictedMethodCallableUsageRuleTest.php index 1d141b0eff..3d4706feb9 100644 --- a/tests/PHPStan/Rules/RestrictedUsage/RestrictedMethodCallableUsageRuleTest.php +++ b/tests/PHPStan/Rules/RestrictedUsage/RestrictedMethodCallableUsageRuleTest.php @@ -4,7 +4,7 @@ use PHPStan\Rules\Rule as TRule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -20,12 +20,9 @@ protected function getRule(): TRule ); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/restricted-method-callable.php'], [ [ 'Cannot call doFoo', diff --git a/tests/PHPStan/Rules/RestrictedUsage/RestrictedStaticMethodCallableUsageRuleTest.php b/tests/PHPStan/Rules/RestrictedUsage/RestrictedStaticMethodCallableUsageRuleTest.php index d0c31e1cbe..353b46ba09 100644 --- a/tests/PHPStan/Rules/RestrictedUsage/RestrictedStaticMethodCallableUsageRuleTest.php +++ b/tests/PHPStan/Rules/RestrictedUsage/RestrictedStaticMethodCallableUsageRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule as TRule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -23,12 +23,9 @@ protected function getRule(): TRule ); } + #[RequiresPhp('>= 8.1')] public function testRule(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/restricted-method-callable.php'], [ [ 'Cannot call doFoo', @@ -37,12 +34,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug12951(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1'); - } - require_once __DIR__ . '/../InternalTag/data/bug-12951-define.php'; $this->analyse([__DIR__ . '/../InternalTag/data/bug-12951-static-method.php'], [ [ diff --git a/tests/PHPStan/Rules/RestrictedUsage/RestrictedStaticMethodUsageRuleTest.php b/tests/PHPStan/Rules/RestrictedUsage/RestrictedStaticMethodUsageRuleTest.php index 9aed48d97b..7bbffc6d40 100644 --- a/tests/PHPStan/Rules/RestrictedUsage/RestrictedStaticMethodUsageRuleTest.php +++ b/tests/PHPStan/Rules/RestrictedUsage/RestrictedStaticMethodUsageRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule as TRule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -33,12 +33,9 @@ public function testRule(): void ]); } + #[RequiresPhp('>= 8.1')] public function testBug12951(): void { - if (PHP_VERSION_ID < 80100) { - self::markTestSkipped('Test requires PHP 8.1'); - } - require_once __DIR__ . '/../InternalTag/data/bug-12951-define.php'; $this->analyse([__DIR__ . '/../InternalTag/data/bug-12951-static-method.php'], [ [ diff --git a/tests/PHPStan/Rules/ScopeFunctionCallStackRuleTest.php b/tests/PHPStan/Rules/ScopeFunctionCallStackRuleTest.php index d59d22835e..e44e1e61a5 100644 --- a/tests/PHPStan/Rules/ScopeFunctionCallStackRuleTest.php +++ b/tests/PHPStan/Rules/ScopeFunctionCallStackRuleTest.php @@ -3,7 +3,7 @@ namespace PHPStan\Rules; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -16,12 +16,9 @@ protected function getRule(): Rule return new ScopeFunctionCallStackRule(); } + #[RequiresPhp('>= 8.0')] public function testRule(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/scope-function-call-stack.php'], [ [ "var_dump\nprint_r\nsleep", diff --git a/tests/PHPStan/Rules/ScopeFunctionCallStackWithParametersRuleTest.php b/tests/PHPStan/Rules/ScopeFunctionCallStackWithParametersRuleTest.php index 38a0aecd61..b784adf647 100644 --- a/tests/PHPStan/Rules/ScopeFunctionCallStackWithParametersRuleTest.php +++ b/tests/PHPStan/Rules/ScopeFunctionCallStackWithParametersRuleTest.php @@ -3,7 +3,7 @@ namespace PHPStan\Rules; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -16,12 +16,9 @@ protected function getRule(): Rule return new ScopeFunctionCallStackWithParametersRule(); } + #[RequiresPhp('>= 8.0')] public function testRule(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/scope-function-call-stack.php'], [ [ "var_dump (\$value)\nprint_r (\$value)\nsleep (\$seconds)", diff --git a/tests/PHPStan/Rules/TooWideTypehints/TooWideMethodReturnTypehintRuleTest.php b/tests/PHPStan/Rules/TooWideTypehints/TooWideMethodReturnTypehintRuleTest.php index 333ecb1c8c..2d84f5dff5 100644 --- a/tests/PHPStan/Rules/TooWideTypehints/TooWideMethodReturnTypehintRuleTest.php +++ b/tests/PHPStan/Rules/TooWideTypehints/TooWideMethodReturnTypehintRuleTest.php @@ -4,7 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -95,11 +96,9 @@ public function testBug5095(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug6158(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } $this->analyse([__DIR__ . '/data/bug-6158.php'], []); } @@ -180,9 +179,9 @@ public static function dataAlwaysCheckFinal(): iterable } /** - * @dataProvider dataAlwaysCheckFinal * @param list $expectedErrors */ + #[DataProvider('dataAlwaysCheckFinal')] public function testAlwaysCheckFinal(bool $checkProtectedAndPublicMethods, array $expectedErrors): void { $this->checkProtectedAndPublicMethods = $checkProtectedAndPublicMethods; diff --git a/tests/PHPStan/Rules/TooWideTypehints/TooWidePropertyTypeRuleTest.php b/tests/PHPStan/Rules/TooWideTypehints/TooWidePropertyTypeRuleTest.php index 1171abd564..213d98342d 100644 --- a/tests/PHPStan/Rules/TooWideTypehints/TooWidePropertyTypeRuleTest.php +++ b/tests/PHPStan/Rules/TooWideTypehints/TooWidePropertyTypeRuleTest.php @@ -6,7 +6,7 @@ use PHPStan\Rules\Properties\PropertyReflectionFinder; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -22,12 +22,9 @@ protected function getRule(): Rule ); } + #[RequiresPhp('>= 8.0')] public function testRule(): void { - if (PHP_VERSION_ID < 80000) { - self::markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/too-wide-property-type.php'], [ [ 'Property TooWidePropertyType\Foo::$foo (int|string) is never assigned string so it can be removed from the property type.', diff --git a/tests/PHPStan/Rules/Traits/ConflictingTraitConstantsRuleTest.php b/tests/PHPStan/Rules/Traits/ConflictingTraitConstantsRuleTest.php index 9515e5dd11..000c694bed 100644 --- a/tests/PHPStan/Rules/Traits/ConflictingTraitConstantsRuleTest.php +++ b/tests/PHPStan/Rules/Traits/ConflictingTraitConstantsRuleTest.php @@ -59,12 +59,9 @@ public function testRule(): void ]); } + #[\PHPUnit\Framework\Attributes\RequiresPhp('>= 8.3')] public function testNativeTypes(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->analyse([__DIR__ . '/data/conflicting-trait-constants-types.php'], [ [ 'Constant ConflictingTraitConstantsTypes\Baz::FOO_CONST (int) overriding constant ConflictingTraitConstantsTypes\Foo::FOO_CONST (int|string) should have the same native type int|string.', diff --git a/tests/PHPStan/Rules/Traits/ConstantsInTraitsRuleTest.php b/tests/PHPStan/Rules/Traits/ConstantsInTraitsRuleTest.php index 2e1e37386c..d8f5746cd3 100644 --- a/tests/PHPStan/Rules/Traits/ConstantsInTraitsRuleTest.php +++ b/tests/PHPStan/Rules/Traits/ConstantsInTraitsRuleTest.php @@ -44,11 +44,10 @@ public static function dataRule(): array } /** - * @dataProvider dataRule - * - * @param list $errors - */ - public function testRule(int $phpVersionId, array $errors): void + * @param list $errors + */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataRule')] + public function testRule(int $phpVersionId, array $errors): void { $this->phpVersionId = $phpVersionId; $this->analyse([__DIR__ . '/data/constants-in-traits.php'], $errors); diff --git a/tests/PHPStan/Rules/Traits/TraitAttributesRuleTest.php b/tests/PHPStan/Rules/Traits/TraitAttributesRuleTest.php index b2f0268efd..d8b9c54d0c 100644 --- a/tests/PHPStan/Rules/Traits/TraitAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Traits/TraitAttributesRuleTest.php @@ -52,12 +52,9 @@ protected function getRule(): Rule ); } + #[\PHPUnit\Framework\Attributes\RequiresPhp('>= 8.0')] public function testRule(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/trait-attributes.php'], [ [ 'Attribute class TraitAttributes\AbstractAttribute is abstract.', @@ -70,12 +67,9 @@ public function testRule(): void ]); } + #[\PHPUnit\Framework\Attributes\RequiresPhp('>= 8.3')] public function testBug12011(): void { - if (PHP_VERSION_ID < 80300) { - $this->markTestSkipped('Test requires PHP 8.3.'); - } - $this->checkExplicitMixed = true; $this->checkImplicitMixed = true; @@ -87,12 +81,9 @@ public function testBug12011(): void ]); } + #[\PHPUnit\Framework\Attributes\RequiresPhp('>= 8.1')] public function testBug12281(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->analyse([__DIR__ . '/data/bug-12281.php'], [ [ 'Attribute class AllowDynamicProperties cannot be used with trait.', diff --git a/tests/PHPStan/Rules/Types/InvalidTypesInUnionRuleTest.php b/tests/PHPStan/Rules/Types/InvalidTypesInUnionRuleTest.php index 426f544dcd..5859945f2b 100644 --- a/tests/PHPStan/Rules/Types/InvalidTypesInUnionRuleTest.php +++ b/tests/PHPStan/Rules/Types/InvalidTypesInUnionRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -30,9 +31,7 @@ public function testRuleOnUnionWithVoid(): void ]); } - /** - * @requires PHP 8.0 - */ + #[RequiresPhp('8.0')] public function testRuleOnUnionWithMixed(): void { $this->analyse([__DIR__ . '/data/invalid-union-with-mixed.php'], [ @@ -71,9 +70,7 @@ public function testRuleOnUnionWithMixed(): void ]); } - /** - * @requires PHP 8.1 - */ + #[RequiresPhp('8.1')] public function testRuleOnUnionWithNever(): void { $this->analyse([__DIR__ . '/data/invalid-union-with-never.php'], [ diff --git a/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php b/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php index 79789b59fa..96b89cf070 100644 --- a/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php +++ b/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php @@ -4,7 +4,8 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -349,9 +350,9 @@ public static function dataLoopInitialAssignments(): array } /** - * @dataProvider dataLoopInitialAssignments * @param list $expectedErrors */ + #[DataProvider('dataLoopInitialAssignments')] public function testLoopInitialAssignments( bool $polluteScopeWithLoopInitialAssignments, bool $checkMaybeUndefinedVariables, @@ -571,10 +572,9 @@ public static function dataForeachPolluteScopeWithAlwaysIterableForeach(): array } /** - * @dataProvider dataForeachPolluteScopeWithAlwaysIterableForeach - * * @param list $errors */ + #[DataProvider('dataForeachPolluteScopeWithAlwaysIterableForeach')] public function testForeachPolluteScopeWithAlwaysIterableForeach(bool $polluteScopeWithAlwaysIterableForeach, array $errors): void { $this->cliArgumentsVariablesRegistered = true; @@ -877,12 +877,9 @@ public function testBug1016b(): void $this->analyse([__DIR__ . '/data/bug-1016b.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug8142(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->cliArgumentsVariablesRegistered = true; $this->polluteScopeWithLoopInitialAssignments = true; $this->checkMaybeUndefinedVariables = true; @@ -958,12 +955,9 @@ public function testBug393(): void $this->analyse([__DIR__ . '/data/bug-393.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug9474(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->cliArgumentsVariablesRegistered = true; $this->polluteScopeWithLoopInitialAssignments = true; $this->checkMaybeUndefinedVariables = true; @@ -971,12 +965,9 @@ public function testBug9474(): void $this->analyse([__DIR__ . '/data/bug-9474.php'], []); } + #[RequiresPhp('>= 8.1')] public function testEnum(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->cliArgumentsVariablesRegistered = true; $this->polluteScopeWithLoopInitialAssignments = true; $this->checkMaybeUndefinedVariables = true; @@ -1029,12 +1020,9 @@ public function testDiscussion10252(): void $this->analyse([__DIR__ . '/data/discussion-10252.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug10418(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->cliArgumentsVariablesRegistered = true; $this->polluteScopeWithLoopInitialAssignments = true; $this->checkMaybeUndefinedVariables = true; @@ -1042,11 +1030,9 @@ public function testBug10418(): void $this->analyse([__DIR__ . '/data/bug-10418.php'], []); } + #[RequiresPhp('>= 8.0')] public function testPassByReferenceIntoNotNullable(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } $this->cliArgumentsVariablesRegistered = true; $this->polluteScopeWithLoopInitialAssignments = true; $this->checkMaybeUndefinedVariables = true; @@ -1068,12 +1054,9 @@ public function testBug10228(): void $this->analyse([__DIR__ . '/data/bug-10228.php'], []); } + #[RequiresPhp('>= 8.4')] public function testPropertyHooks(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->cliArgumentsVariablesRegistered = true; $this->polluteScopeWithLoopInitialAssignments = true; $this->checkMaybeUndefinedVariables = true; diff --git a/tests/PHPStan/Rules/Variables/EmptyRuleTest.php b/tests/PHPStan/Rules/Variables/EmptyRuleTest.php index 21372b778b..f0c0343340 100644 --- a/tests/PHPStan/Rules/Variables/EmptyRuleTest.php +++ b/tests/PHPStan/Rules/Variables/EmptyRuleTest.php @@ -7,7 +7,8 @@ use PHPStan\Rules\Properties\PropertyReflectionFinder; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -113,12 +114,9 @@ public function testBug6974TreatPhpDocTypesAsCertain(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug7109(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/../Properties/data/bug-7109.php'], [ @@ -194,9 +192,7 @@ public static function dataBug9403(): iterable yield [false]; } - /** - * @dataProvider dataBug9403 - */ + #[DataProvider('dataBug9403')] public function testBug9403(bool $treatPhpDocTypesAsCertain): void { $this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain; @@ -211,12 +207,9 @@ public function testBug12658(): void $this->analyse([__DIR__ . '/data/bug-12658.php'], []); } + #[RequiresPhp('>= 8.0')] public function testIssetAfterRememberedConstructor(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/isset-after-remembered-constructor.php'], [ diff --git a/tests/PHPStan/Rules/Variables/IssetRuleTest.php b/tests/PHPStan/Rules/Variables/IssetRuleTest.php index c033e020f5..0acd26902a 100644 --- a/tests/PHPStan/Rules/Variables/IssetRuleTest.php +++ b/tests/PHPStan/Rules/Variables/IssetRuleTest.php @@ -7,7 +7,7 @@ use PHPStan\Rules\Properties\PropertyReflectionFinder; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -332,12 +332,9 @@ public function testNullsafe(): void ]); } + #[RequiresPhp('>= 8.0')] public function testBug7109(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/../Properties/data/bug-7109.php'], [ @@ -390,12 +387,9 @@ public function testBug6997(): void $this->analyse([__DIR__ . '/data/bug-6997.php'], []); } + #[RequiresPhp('>= 8.1')] public function testBug7776(): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-7776.php'], []); @@ -453,12 +447,9 @@ public function testBug10064(): void $this->analyse([__DIR__ . '/data/bug-10064.php'], []); } + #[RequiresPhp('>= 8.4')] public function testVirtualProperty(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/isset-virtual-property.php'], [ [ diff --git a/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php b/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php index ba73fbe2fb..15a04e3eb9 100644 --- a/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php +++ b/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php @@ -7,6 +7,7 @@ use PHPStan\Rules\Properties\PropertyReflectionFinder; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use const PHP_VERSION_ID; /** @@ -267,12 +268,9 @@ public function testBug5933(): void $this->analyse([__DIR__ . '/data/bug-5933.php'], []); } + #[RequiresPhp('>= 8.0')] public function testBug7109(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/../Properties/data/bug-7109.php'], [ @@ -351,12 +349,9 @@ public function testBug10610(): void $this->analyse([__DIR__ . '/data/bug-10610.php'], []); } + #[RequiresPhp('>= 8.4')] public function testBug12553(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4.'); - } - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-12553.php'], []); } diff --git a/tests/PHPStan/Rules/Variables/UnsetRuleTest.php b/tests/PHPStan/Rules/Variables/UnsetRuleTest.php index cfe63c0dd7..c9cb149958 100644 --- a/tests/PHPStan/Rules/Variables/UnsetRuleTest.php +++ b/tests/PHPStan/Rules/Variables/UnsetRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Rules\Properties\PropertyReflectionFinder; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use function array_merge; use const PHP_VERSION_ID; @@ -142,12 +143,9 @@ public function testBug12421(): void $this->analyse([__DIR__ . '/data/bug-12421.php'], $errors); } + #[RequiresPhp('>= 8.4')] public function testUnsetHookedProperty(): void { - if (PHP_VERSION_ID < 80400) { - $this->markTestSkipped('Test requires PHP 8.4 or later.'); - } - $this->analyse([__DIR__ . '/data/unset-hooked-property.php'], [ [ 'Cannot unset hooked UnsetHookedProperty\User::$name property.', diff --git a/tests/PHPStan/Rules/Variables/VariableCloningRuleTest.php b/tests/PHPStan/Rules/Variables/VariableCloningRuleTest.php index 869ff35c31..b9e7a170f0 100644 --- a/tests/PHPStan/Rules/Variables/VariableCloningRuleTest.php +++ b/tests/PHPStan/Rules/Variables/VariableCloningRuleTest.php @@ -5,7 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; -use const PHP_VERSION_ID; +use PHPUnit\Framework\Attributes\RequiresPhp; /** * @extends RuleTestCase @@ -49,12 +49,9 @@ public function testClone(): void ]); } + #[RequiresPhp('>= 8.0')] public function testRuleWithNullsafeVariant(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('Test requires PHP 8.0.'); - } - $this->analyse([__DIR__ . '/data/variable-cloning-nullsafe.php'], [ [ 'Cannot clone stdClass|null.', diff --git a/tests/PHPStan/Testing/TypeInferenceTestCaseTest.php b/tests/PHPStan/Testing/TypeInferenceTestCaseTest.php index 5f363661a5..cce8bd958a 100644 --- a/tests/PHPStan/Testing/TypeInferenceTestCaseTest.php +++ b/tests/PHPStan/Testing/TypeInferenceTestCaseTest.php @@ -4,6 +4,7 @@ use PHPStan\File\FileHelper; use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Attributes\DataProvider; use function array_values; use function sprintf; @@ -80,9 +81,7 @@ public static function dataFileAssertionFailedErrors(): iterable ]; } - /** - * @dataProvider dataFileAssertionFailedErrors - */ + #[DataProvider('dataFileAssertionFailedErrors')] public function testFileAssertionFailedErrors(string $filePath, string $errorMessage): void { $this->expectException(AssertionFailedError::class); diff --git a/tests/PHPStan/TrinaryLogicTest.php b/tests/PHPStan/TrinaryLogicTest.php index 763f913f6b..906422f83a 100644 --- a/tests/PHPStan/TrinaryLogicTest.php +++ b/tests/PHPStan/TrinaryLogicTest.php @@ -3,6 +3,7 @@ namespace PHPStan; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class TrinaryLogicTest extends PHPStanTestCase { @@ -28,9 +29,7 @@ public static function dataAnd(): array ]; } - /** - * @dataProvider dataAnd - */ + #[DataProvider('dataAnd')] public function testAnd( TrinaryLogic $expectedResult, TrinaryLogic $value, @@ -40,9 +39,7 @@ public function testAnd( $this->assertTrue($expectedResult->equals($value->and(...$operands))); } - /** - * @dataProvider dataAnd - */ + #[DataProvider('dataAnd')] public function testLazyAnd( TrinaryLogic $expectedResult, TrinaryLogic $value, @@ -73,9 +70,7 @@ public static function dataOr(): array ]; } - /** - * @dataProvider dataOr - */ + #[DataProvider('dataOr')] public function testOr( TrinaryLogic $expectedResult, TrinaryLogic $value, @@ -85,9 +80,7 @@ public function testOr( $this->assertTrue($expectedResult->equals($value->or(...$operands))); } - /** - * @dataProvider dataOr - */ + #[DataProvider('dataOr')] public function testLazyOr( TrinaryLogic $expectedResult, TrinaryLogic $value, @@ -106,9 +99,7 @@ public static function dataNegate(): array ]; } - /** - * @dataProvider dataNegate - */ + #[DataProvider('dataNegate')] public function testNegate(TrinaryLogic $expectedResult, TrinaryLogic $operand): void { $this->assertTrue($expectedResult->equals($operand->negate())); @@ -153,9 +144,7 @@ public static function dataCompareTo(): array ]; } - /** - * @dataProvider dataCompareTo - */ + #[DataProvider('dataCompareTo')] public function testCompareTo(TrinaryLogic $first, TrinaryLogic $second, ?TrinaryLogic $expected): void { $this->assertSame( @@ -164,9 +153,7 @@ public function testCompareTo(TrinaryLogic $first, TrinaryLogic $second, ?Trinar ); } - /** - * @dataProvider dataCompareTo - */ + #[DataProvider('dataCompareTo')] public function testCompareToInversed(TrinaryLogic $first, TrinaryLogic $second, ?TrinaryLogic $expected): void { $this->assertSame( diff --git a/tests/PHPStan/Type/Accessory/HasMethodTypeTest.php b/tests/PHPStan/Type/Accessory/HasMethodTypeTest.php index f5314e378d..057ae63a2f 100644 --- a/tests/PHPStan/Type/Accessory/HasMethodTypeTest.php +++ b/tests/PHPStan/Type/Accessory/HasMethodTypeTest.php @@ -17,6 +17,7 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class HasMethodTypeTest extends PHPStanTestCase @@ -136,9 +137,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(HasMethodType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -186,9 +185,7 @@ public static function dataIsSubTypeOf(): array ]; } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOf(HasMethodType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSubTypeOf($otherType); @@ -199,9 +196,7 @@ public function testIsSubTypeOf(HasMethodType $type, Type $otherType, TrinaryLog ); } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOfInversed(HasMethodType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $otherType->isSuperTypeOf($type); diff --git a/tests/PHPStan/Type/Accessory/HasPropertyTypeTest.php b/tests/PHPStan/Type/Accessory/HasPropertyTypeTest.php index e9cb484e42..087bd96910 100644 --- a/tests/PHPStan/Type/Accessory/HasPropertyTypeTest.php +++ b/tests/PHPStan/Type/Accessory/HasPropertyTypeTest.php @@ -16,6 +16,7 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; use const PHP_VERSION_ID; @@ -102,9 +103,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(HasPropertyType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -147,9 +146,7 @@ public static function dataIsSubTypeOf(): array ]; } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOf(HasPropertyType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSubTypeOf($otherType); @@ -160,9 +157,7 @@ public function testIsSubTypeOf(HasPropertyType $type, Type $otherType, TrinaryL ); } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOfInversed(HasPropertyType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $otherType->isSuperTypeOf($type); diff --git a/tests/PHPStan/Type/ArrayTypeTest.php b/tests/PHPStan/Type/ArrayTypeTest.php index 652504c2e2..9b7b2cfcaf 100644 --- a/tests/PHPStan/Type/ArrayTypeTest.php +++ b/tests/PHPStan/Type/ArrayTypeTest.php @@ -12,6 +12,7 @@ use PHPStan\Type\Generic\TemplateTypeFactory; use PHPStan\Type\Generic\TemplateTypeScope; use PHPStan\Type\Generic\TemplateTypeVariance; +use PHPUnit\Framework\Attributes\DataProvider; use function array_map; use function sprintf; @@ -85,9 +86,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(ArrayType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -147,9 +146,7 @@ public static function dataAccepts(): array ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts( ArrayType $acceptingType, Type $acceptedType, @@ -177,9 +174,7 @@ public static function dataDescribe(): array ]; } - /** - * @dataProvider dataDescribe - */ + #[DataProvider('dataDescribe')] public function testDescribe( ArrayType $type, string $expectedDescription, @@ -261,9 +256,9 @@ public static function dataInferTemplateTypes(): array } /** - * @dataProvider dataInferTemplateTypes * @param array $expectedTypes */ + #[DataProvider('dataInferTemplateTypes')] public function testResolveTemplateTypes(Type $received, Type $template, array $expectedTypes): void { $result = $template->inferTemplateTypes($received); diff --git a/tests/PHPStan/Type/BenevolentUnionTypeTest.php b/tests/PHPStan/Type/BenevolentUnionTypeTest.php index 97aece38b0..0610f74c4f 100644 --- a/tests/PHPStan/Type/BenevolentUnionTypeTest.php +++ b/tests/PHPStan/Type/BenevolentUnionTypeTest.php @@ -14,6 +14,7 @@ use PHPStan\Type\Accessory\NonEmptyArrayType; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantStringType; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class BenevolentUnionTypeTest extends PHPStanTestCase @@ -37,7 +38,7 @@ public static function dataCanAccessProperties(): Iterator ]; } - /** @dataProvider dataCanAccessProperties */ + #[DataProvider('dataCanAccessProperties')] public function testCanAccessProperties(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->canAccessProperties(); @@ -75,7 +76,7 @@ public static function dataHasProperty(): Iterator ]; } - /** @dataProvider dataHasProperty */ + #[DataProvider('dataHasProperty')] public function testHasProperty(BenevolentUnionType $type, string $propertyName, TrinaryLogic $expectedResult): void { $actualResult = $type->hasProperty($propertyName); @@ -104,7 +105,7 @@ public static function dataCanCallMethods(): Iterator ]; } - /** @dataProvider dataCanCallMethods */ + #[DataProvider('dataCanCallMethods')] public function testCanCanCallMethods(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->canCallMethods(); @@ -139,7 +140,7 @@ public static function dataHasMethod(): Iterator ]; } - /** @dataProvider dataHasMethod */ + #[DataProvider('dataHasMethod')] public function testHasMethod(BenevolentUnionType $type, string $methodName, TrinaryLogic $expectedResult): void { $actualResult = $type->hasMethod($methodName); @@ -168,7 +169,7 @@ public static function dataCanAccessConstants(): Iterator ]; } - /** @dataProvider dataCanAccessConstants */ + #[DataProvider('dataCanAccessConstants')] public function testCanAccessConstants(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->canAccessConstants(); @@ -203,7 +204,7 @@ public static function dataIsIterable(): Iterator ]; } - /** @dataProvider dataIsIterable */ + #[DataProvider('dataIsIterable')] public function testIsIterable(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isIterable(); @@ -238,7 +239,7 @@ public static function dataIsIterableAtLeastOnce(): Iterator ]; } - /** @dataProvider dataIsIterableAtLeastOnce */ + #[DataProvider('dataIsIterableAtLeastOnce')] public function testIsIterableAtLeastOnce(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isIterableAtLeastOnce(); @@ -267,7 +268,7 @@ public static function dataIsArray(): Iterator ]; } - /** @dataProvider dataIsArray */ + #[DataProvider('dataIsArray')] public function testIsArray(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isArray(); @@ -299,7 +300,7 @@ public static function dataIsString(): Iterator ]; } - /** @dataProvider dataIsString */ + #[DataProvider('dataIsString')] public function testIsString(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isString(); @@ -330,7 +331,7 @@ public static function dataIsNumericString(): Iterator ]; } - /** @dataProvider dataIsNumericString */ + #[DataProvider('dataIsNumericString')] public function testIsNumericString(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isNumericString(); @@ -361,7 +362,7 @@ public static function dataIsNonFalsyString(): Iterator ]; } - /** @dataProvider dataIsNonFalsyString */ + #[DataProvider('dataIsNonFalsyString')] public function testIsNonFalsyString(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isNonFalsyString(); @@ -392,7 +393,7 @@ public static function dataIsLiteralString(): Iterator ]; } - /** @dataProvider dataIsLiteralString */ + #[DataProvider('dataIsLiteralString')] public function testIsLiteralString(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isLiteralString(); @@ -427,7 +428,7 @@ public static function dataIsOffsetAccesible(): Iterator ]; } - /** @dataProvider dataIsOffsetAccesible */ + #[DataProvider('dataIsOffsetAccesible')] public function testIsOffsetAccessible(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isOffsetAccessible(); @@ -465,7 +466,7 @@ public static function dataHasOffsetValueType(): Iterator ]; } - /** @dataProvider dataHasOffsetValueType */ + #[DataProvider('dataHasOffsetValueType')] public function testHasOffsetValue(BenevolentUnionType $type, Type $offsetType, TrinaryLogic $expectedResult): void { $actualResult = $type->hasOffsetValueType($offsetType); @@ -494,7 +495,7 @@ public static function dataIsCallable(): Iterator ]; } - /** @dataProvider dataIsCallable */ + #[DataProvider('dataIsCallable')] public function testIsCallable(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isCallable(); @@ -523,7 +524,7 @@ public static function dataIsCloneable(): Iterator ]; } - /** @dataProvider dataIsCloneable */ + #[DataProvider('dataIsCloneable')] public function testIsCloneable(BenevolentUnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isCloneable(); diff --git a/tests/PHPStan/Type/BitwiseFlagHelperTest.php b/tests/PHPStan/Type/BitwiseFlagHelperTest.php index eac74b92ce..e210842df7 100644 --- a/tests/PHPStan/Type/BitwiseFlagHelperTest.php +++ b/tests/PHPStan/Type/BitwiseFlagHelperTest.php @@ -12,6 +12,7 @@ use PHPStan\Analyser\ScopeFactory; use PHPStan\Testing\PHPStanTestCase; use PHPStan\TrinaryLogic; +use PHPUnit\Framework\Attributes\DataProvider; use function defined; use function sprintf; @@ -117,11 +118,11 @@ public static function dataJsonExprContainsConst(): array } /** - * @dataProvider dataUnknownConstants - * @dataProvider dataJsonExprContainsConst * * @param non-empty-string $constName */ + #[DataProvider('dataUnknownConstants')] + #[DataProvider('dataJsonExprContainsConst')] public function testExprContainsConst(Expr $expr, string $constName, TrinaryLogic $expected): void { /** @var ScopeFactory $scopeFactory */ diff --git a/tests/PHPStan/Type/BooleanTypeTest.php b/tests/PHPStan/Type/BooleanTypeTest.php index 8b8b7a1ff8..c1d189683c 100644 --- a/tests/PHPStan/Type/BooleanTypeTest.php +++ b/tests/PHPStan/Type/BooleanTypeTest.php @@ -6,6 +6,7 @@ use PHPStan\TrinaryLogic; use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\Constant\ConstantIntegerType; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class BooleanTypeTest extends PHPStanTestCase @@ -47,9 +48,7 @@ public static function dataAccepts(): array ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts(BooleanType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->accepts($otherType, true)->result; @@ -93,9 +92,7 @@ public static function dataIsSuperTypeOf(): iterable ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(BooleanType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -147,9 +144,7 @@ public static function dataEquals(): array ]; } - /** - * @dataProvider dataEquals - */ + #[DataProvider('dataEquals')] public function testEquals(BooleanType $type, Type $otherType, bool $expectedResult): void { $actualResult = $type->equals($otherType); diff --git a/tests/PHPStan/Type/CallableTypeTest.php b/tests/PHPStan/Type/CallableTypeTest.php index 30b543058e..7ea4c0f30e 100644 --- a/tests/PHPStan/Type/CallableTypeTest.php +++ b/tests/PHPStan/Type/CallableTypeTest.php @@ -16,6 +16,7 @@ use PHPStan\Type\Generic\TemplateTypeFactory; use PHPStan\Type\Generic\TemplateTypeScope; use PHPStan\Type\Generic\TemplateTypeVariance; +use PHPUnit\Framework\Attributes\DataProvider; use function array_map; use function sprintf; @@ -61,9 +62,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(CallableType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -140,9 +139,7 @@ public static function dataIsSubTypeOf(): array ]; } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOf(CallableType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSubTypeOf($otherType); @@ -153,9 +150,7 @@ public function testIsSubTypeOf(CallableType $type, Type $otherType, TrinaryLogi ); } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOfInversed(CallableType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $otherType->isSuperTypeOf($type); @@ -267,9 +262,9 @@ public static function dataInferTemplateTypes(): array } /** - * @dataProvider dataInferTemplateTypes * @param array $expectedTypes */ + #[DataProvider('dataInferTemplateTypes')] public function testResolveTemplateTypes(Type $received, Type $template, array $expectedTypes): void { $result = $template->inferTemplateTypes($received); @@ -412,9 +407,7 @@ public static function dataAccepts(): array ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts( CallableType $type, Type $acceptedType, diff --git a/tests/PHPStan/Type/ClassStringTypeTest.php b/tests/PHPStan/Type/ClassStringTypeTest.php index 06dd312d59..bfb87e2fa8 100644 --- a/tests/PHPStan/Type/ClassStringTypeTest.php +++ b/tests/PHPStan/Type/ClassStringTypeTest.php @@ -7,6 +7,7 @@ use PHPStan\TrinaryLogic; use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\Generic\GenericClassStringType; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use function sprintf; @@ -39,9 +40,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(ClassStringType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -103,9 +102,7 @@ public static function dataAccepts(): iterable ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts(ClassStringType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->accepts($otherType, true)->result; @@ -132,9 +129,7 @@ public static function dataEquals(): array ]; } - /** - * @dataProvider dataEquals - */ + #[DataProvider('dataEquals')] public function testEquals(ClassStringType $type, Type $otherType, bool $expectedResult): void { $actualResult = $type->equals($otherType); diff --git a/tests/PHPStan/Type/ClosureTypeFactoryTest.php b/tests/PHPStan/Type/ClosureTypeFactoryTest.php index d91e609ae5..fa2180ea5d 100644 --- a/tests/PHPStan/Type/ClosureTypeFactoryTest.php +++ b/tests/PHPStan/Type/ClosureTypeFactoryTest.php @@ -4,6 +4,7 @@ use Closure; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ClosureTypeFactoryTest extends PHPStanTestCase { @@ -21,8 +22,8 @@ public static function dataFromClosureObjectReturnType(): array /** * @param Closure(): mixed $closure - * @dataProvider dataFromClosureObjectReturnType */ + #[DataProvider('dataFromClosureObjectReturnType')] public function testFromClosureObjectReturnType(Closure $closure, string $returnType): void { $closureType = $this->getClosureType($closure); @@ -48,8 +49,8 @@ public static function dataFromClosureObjectParameter(): array /** * @param Closure(): mixed $closure - * @dataProvider dataFromClosureObjectParameter */ + #[DataProvider('dataFromClosureObjectParameter')] public function testFromClosureObjectParameter(Closure $closure, int $index, string $type): void { $closureType = $this->getClosureType($closure); diff --git a/tests/PHPStan/Type/ClosureTypeTest.php b/tests/PHPStan/Type/ClosureTypeTest.php index 0977874bcc..f5ef07239e 100644 --- a/tests/PHPStan/Type/ClosureTypeTest.php +++ b/tests/PHPStan/Type/ClosureTypeTest.php @@ -5,6 +5,7 @@ use Closure; use PHPStan\Testing\PHPStanTestCase; use PHPStan\TrinaryLogic; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class ClosureTypeTest extends PHPStanTestCase @@ -91,9 +92,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf( Type $type, Type $otherType, diff --git a/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php b/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php index a19e0c8f5a..623c86e3ec 100644 --- a/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php +++ b/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php @@ -25,6 +25,7 @@ use PHPStan\Type\TypeCombinator; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function array_map; use function sprintf; @@ -409,9 +410,7 @@ public static function dataAccepts(): iterable ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts(Type $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->accepts($otherType, true)->result; @@ -693,9 +692,7 @@ public static function dataIsSuperTypeOf(): iterable ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(ConstantArrayType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -811,9 +808,9 @@ public static function dataInferTemplateTypes(): array } /** - * @dataProvider dataInferTemplateTypes * @param array $expectedTypes */ + #[DataProvider('dataInferTemplateTypes')] public function testResolveTemplateTypes(Type $received, Type $template, array $expectedTypes): void { $result = $template->inferTemplateTypes($received); @@ -824,9 +821,7 @@ public function testResolveTemplateTypes(Type $received, Type $template, array $ ); } - /** - * @dataProvider dataIsCallable - */ + #[DataProvider('dataIsCallable')] public function testIsCallable(ConstantArrayType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isCallable(); @@ -1034,9 +1029,7 @@ public static function dataValuesArray(): iterable ]; } - /** - * @dataProvider dataValuesArray - */ + #[DataProvider('dataValuesArray')] public function testValuesArray(ConstantArrayType $type, ConstantArrayType $expectedType): void { $actualType = $type->getValuesArray(); diff --git a/tests/PHPStan/Type/Constant/ConstantFloatTypeTest.php b/tests/PHPStan/Type/Constant/ConstantFloatTypeTest.php index 623e9e11a8..83260d706c 100644 --- a/tests/PHPStan/Type/Constant/ConstantFloatTypeTest.php +++ b/tests/PHPStan/Type/Constant/ConstantFloatTypeTest.php @@ -4,6 +4,7 @@ use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; class ConstantFloatTypeTest extends PHPStanTestCase { @@ -38,9 +39,7 @@ public static function dataDescribe(): array ]; } - /** - * @dataProvider dataDescribe - */ + #[DataProvider('dataDescribe')] public function testDescribe( ConstantFloatType $type, string $expectedDescription, diff --git a/tests/PHPStan/Type/Constant/ConstantIntegerTypeTest.php b/tests/PHPStan/Type/Constant/ConstantIntegerTypeTest.php index 1319bc0c66..6e4fa1ead7 100644 --- a/tests/PHPStan/Type/Constant/ConstantIntegerTypeTest.php +++ b/tests/PHPStan/Type/Constant/ConstantIntegerTypeTest.php @@ -7,6 +7,7 @@ use PHPStan\Type\IntegerType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class ConstantIntegerTypeTest extends PHPStanTestCase @@ -33,9 +34,7 @@ public static function dataAccepts(): iterable ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts(ConstantIntegerType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->accepts($otherType, true)->result; @@ -67,9 +66,7 @@ public static function dataIsSuperTypeOf(): iterable ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(ConstantIntegerType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); diff --git a/tests/PHPStan/Type/Constant/ConstantStringTypeTest.php b/tests/PHPStan/Type/Constant/ConstantStringTypeTest.php index fee3036b3d..d07d72d48a 100644 --- a/tests/PHPStan/Type/Constant/ConstantStringTypeTest.php +++ b/tests/PHPStan/Type/Constant/ConstantStringTypeTest.php @@ -17,6 +17,7 @@ use PHPStan\Type\StaticType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use Throwable; use function sprintf; @@ -136,9 +137,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(ConstantStringType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); diff --git a/tests/PHPStan/Type/Constant/OversizedArrayBuilderTest.php b/tests/PHPStan/Type/Constant/OversizedArrayBuilderTest.php index 5051471e0d..185127d984 100644 --- a/tests/PHPStan/Type/Constant/OversizedArrayBuilderTest.php +++ b/tests/PHPStan/Type/Constant/OversizedArrayBuilderTest.php @@ -10,6 +10,7 @@ use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; class OversizedArrayBuilderTest extends PHPStanTestCase { @@ -62,9 +63,7 @@ public static function dataBuild(): iterable ]; } - /** - * @dataProvider dataBuild - */ + #[DataProvider('dataBuild')] public function testBuild(string $sourceCode, string $expectedTypeDescription): void { $parser = self::getParser(); diff --git a/tests/PHPStan/Type/Enum/EnumCaseObjectTypeTest.php b/tests/PHPStan/Type/Enum/EnumCaseObjectTypeTest.php index a0db6c2344..a4e8527c93 100644 --- a/tests/PHPStan/Type/Enum/EnumCaseObjectTypeTest.php +++ b/tests/PHPStan/Type/Enum/EnumCaseObjectTypeTest.php @@ -10,8 +10,9 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use function sprintf; -use const PHP_VERSION_ID; class EnumCaseObjectTypeTest extends PHPStanTestCase { @@ -102,14 +103,10 @@ public static function dataIsSuperTypeOf(): iterable ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[RequiresPhp('>= 8.1')] + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(Type $type, Type $otherType, TrinaryLogic $expectedResult): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } $actualResult = $type->isSuperTypeOf($otherType); $this->assertSame( $expectedResult->describe(), @@ -204,19 +201,14 @@ public static function dataAccepts(): iterable ]; } - /** - * @dataProvider dataAccepts - */ + #[RequiresPhp('>= 8.1')] + #[DataProvider('dataAccepts')] public function testAccepts( Type $type, Type $acceptedType, TrinaryLogic $expectedResult, ): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $this->assertSame( $expectedResult->describe(), $type->accepts($acceptedType, true)->result->describe(), diff --git a/tests/PHPStan/Type/FloatTypeTest.php b/tests/PHPStan/Type/FloatTypeTest.php index 43b7083d8f..878e1d49f4 100644 --- a/tests/PHPStan/Type/FloatTypeTest.php +++ b/tests/PHPStan/Type/FloatTypeTest.php @@ -7,6 +7,7 @@ use PHPStan\Type\Constant\ConstantFloatType; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class FloatTypeTest extends PHPStanTestCase @@ -60,9 +61,7 @@ public static function dataAccepts(): array ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts(Type $otherType, TrinaryLogic $expectedResult): void { $type = new FloatType(); @@ -120,9 +119,7 @@ public static function dataEquals(): array ]; } - /** - * @dataProvider dataEquals - */ + #[DataProvider('dataEquals')] public function testEquals(FloatType $type, Type $otherType, bool $expectedResult): void { $actualResult = $type->equals($otherType); diff --git a/tests/PHPStan/Type/Generic/GenericClassStringTypeTest.php b/tests/PHPStan/Type/Generic/GenericClassStringTypeTest.php index 3dd8b17a11..9f5b836898 100644 --- a/tests/PHPStan/Type/Generic/GenericClassStringTypeTest.php +++ b/tests/PHPStan/Type/Generic/GenericClassStringTypeTest.php @@ -20,6 +20,7 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use Throwable; use function sprintf; @@ -158,9 +159,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(GenericClassStringType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -275,9 +274,7 @@ public static function dataAccepts(): array ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts( GenericClassStringType $acceptingType, Type $acceptedType, @@ -320,9 +317,7 @@ public static function dataEquals(): array ]; } - /** - * @dataProvider dataEquals - */ + #[DataProvider('dataEquals')] public function testEquals(GenericClassStringType $type, Type $otherType, bool $expected): void { $verbosityLevel = VerbosityLevel::precise(); diff --git a/tests/PHPStan/Type/Generic/GenericObjectTypeTest.php b/tests/PHPStan/Type/Generic/GenericObjectTypeTest.php index e7df51b9e9..2f3733c363 100644 --- a/tests/PHPStan/Type/Generic/GenericObjectTypeTest.php +++ b/tests/PHPStan/Type/Generic/GenericObjectTypeTest.php @@ -21,6 +21,7 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use ReflectionClass; use stdClass; use Traversable; @@ -261,10 +262,8 @@ public static function dataTypeProjections(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - * @dataProvider dataTypeProjections - */ + #[DataProvider('dataIsSuperTypeOf')] + #[DataProvider('dataTypeProjections')] public function testIsSuperTypeOf(Type $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -331,10 +330,8 @@ public static function dataAccepts(): array ]; } - /** - * @dataProvider dataAccepts - * @dataProvider dataTypeProjections - */ + #[DataProvider('dataAccepts')] + #[DataProvider('dataTypeProjections')] public function testAccepts( Type $acceptingType, Type $acceptedType, @@ -449,9 +446,9 @@ public static function dataInferTemplateTypes(): array } /** - * @dataProvider dataInferTemplateTypes * @param array $expectedTypes */ + #[DataProvider('dataInferTemplateTypes')] public function testResolveTemplateTypes(Type $received, Type $template, array $expectedTypes): void { $result = $template->inferTemplateTypes($received); @@ -957,10 +954,9 @@ public static function dataGetReferencedTypeArguments(): array } /** - * @dataProvider dataGetReferencedTypeArguments - * * @param array $expectedReferences */ + #[DataProvider('dataGetReferencedTypeArguments')] public function testGetReferencedTypeArguments(TemplateTypeVariance $positionVariance, Type $type, array $expectedReferences): void { $result = []; diff --git a/tests/PHPStan/Type/Generic/TemplateTypeMapTest.php b/tests/PHPStan/Type/Generic/TemplateTypeMapTest.php index 242d66da69..c6502e85f6 100644 --- a/tests/PHPStan/Type/Generic/TemplateTypeMapTest.php +++ b/tests/PHPStan/Type/Generic/TemplateTypeMapTest.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use PHPStan\Type\ObjectType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class TemplateTypeMapTest extends TestCase @@ -55,7 +56,7 @@ public static function dataUnionWithLowerBoundTypes(): iterable ]; } - /** @dataProvider dataUnionWithLowerBoundTypes */ + #[DataProvider('dataUnionWithLowerBoundTypes')] public function testUnionWithLowerBoundTypes(TemplateTypeMap $map, string $expectedTDescription): void { $this->assertFalse($map->isEmpty()); diff --git a/tests/PHPStan/Type/Generic/TemplateTypeVarianceTest.php b/tests/PHPStan/Type/Generic/TemplateTypeVarianceTest.php index a7db656211..107ca6963f 100644 --- a/tests/PHPStan/Type/Generic/TemplateTypeVarianceTest.php +++ b/tests/PHPStan/Type/Generic/TemplateTypeVarianceTest.php @@ -9,6 +9,7 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function sprintf; @@ -76,9 +77,7 @@ public static function dataIsValidVariance(): iterable } } - /** - * @dataProvider dataIsValidVariance - */ + #[DataProvider('dataIsValidVariance')] public function testIsValidVariance( TemplateTypeVariance $variance, Type $a, diff --git a/tests/PHPStan/Type/IntegerTypeTest.php b/tests/PHPStan/Type/IntegerTypeTest.php index 6b7dc51958..e6512b6f8c 100644 --- a/tests/PHPStan/Type/IntegerTypeTest.php +++ b/tests/PHPStan/Type/IntegerTypeTest.php @@ -7,6 +7,7 @@ use PHPStan\Type\Constant\ConstantFloatType; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class IntegerTypeTest extends PHPStanTestCase @@ -48,9 +49,7 @@ public static function dataAccepts(): array ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts(IntegerType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->accepts($otherType, true)->result; @@ -94,9 +93,7 @@ public static function dataIsSuperTypeOf(): iterable ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(IntegerType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -153,9 +150,7 @@ public static function dataEquals(): array ]; } - /** - * @dataProvider dataEquals - */ + #[DataProvider('dataEquals')] public function testEquals(IntegerType $type, Type $otherType, bool $expectedResult): void { $actualResult = $type->equals($otherType); diff --git a/tests/PHPStan/Type/IntersectionTypeTest.php b/tests/PHPStan/Type/IntersectionTypeTest.php index f4143a0f37..80f6c21b95 100644 --- a/tests/PHPStan/Type/IntersectionTypeTest.php +++ b/tests/PHPStan/Type/IntersectionTypeTest.php @@ -17,6 +17,7 @@ use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\Enum\EnumCaseObjectType; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use Test\ClassWithToString; use Traversable; @@ -68,9 +69,7 @@ public static function dataAccepts(): Iterator ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts(IntersectionType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->accepts($otherType, true)->result; @@ -111,9 +110,7 @@ public static function dataIsCallable(): array ]; } - /** - * @dataProvider dataIsCallable - */ + #[DataProvider('dataIsCallable')] public function testIsCallable(IntersectionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isCallable(); @@ -234,9 +231,7 @@ public static function dataIsSuperTypeOf(): Iterator ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(IntersectionType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -334,9 +329,7 @@ public static function dataIsSubTypeOf(): Iterator ]; } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOf(IntersectionType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSubTypeOf($otherType); @@ -347,9 +340,7 @@ public function testIsSubTypeOf(IntersectionType $type, Type $otherType, Trinary ); } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOfInversed(IntersectionType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $otherType->isSuperTypeOf($type); @@ -387,9 +378,9 @@ public static function dataGetEnumCases(): iterable } /** - * @dataProvider dataGetEnumCases * @param list $expectedEnumCases */ + #[DataProvider('dataGetEnumCases')] public function testGetEnumCases( IntersectionType $type, array $expectedEnumCases, @@ -723,9 +714,7 @@ public static function dataDescribe(): iterable ]; } - /** - * @dataProvider dataDescribe - */ + #[DataProvider('dataDescribe')] public function testDescribe(IntersectionType $type, VerbosityLevel $verbosityLevel, string $expected): void { static::assertSame($expected, $type->describe($verbosityLevel)); diff --git a/tests/PHPStan/Type/IterableTypeTest.php b/tests/PHPStan/Type/IterableTypeTest.php index ec6763a39c..557caeb1ad 100644 --- a/tests/PHPStan/Type/IterableTypeTest.php +++ b/tests/PHPStan/Type/IterableTypeTest.php @@ -11,6 +11,7 @@ use PHPStan\Type\Generic\TemplateTypeFactory; use PHPStan\Type\Generic\TemplateTypeScope; use PHPStan\Type\Generic\TemplateTypeVariance; +use PHPUnit\Framework\Attributes\DataProvider; use function array_map; use function sprintf; @@ -58,9 +59,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(IterableType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -157,9 +156,7 @@ public static function dataIsSubTypeOf(): array ]; } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOf(IterableType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSubTypeOf($otherType); @@ -170,9 +167,7 @@ public function testIsSubTypeOf(IterableType $type, Type $otherType, TrinaryLogi ); } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOfInversed(IterableType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $otherType->isSuperTypeOf($type); @@ -235,9 +230,9 @@ public static function dataInferTemplateTypes(): array } /** - * @dataProvider dataInferTemplateTypes * @param array $expectedTypes */ + #[DataProvider('dataInferTemplateTypes')] public function testResolveTemplateTypes(Type $received, Type $template, array $expectedTypes): void { $result = $template->inferTemplateTypes($received); @@ -285,9 +280,7 @@ public static function dataDescribe(): array ]; } - /** - * @dataProvider dataDescribe - */ + #[DataProvider('dataDescribe')] public function testDescribe(Type $type, string $expect): void { $result = $type->describe(VerbosityLevel::typeOnly()); @@ -324,9 +317,7 @@ public static function dataAccepts(): array ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts(IterableType $iterableType, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $iterableType->accepts($otherType, true)->result; diff --git a/tests/PHPStan/Type/MixedTypeTest.php b/tests/PHPStan/Type/MixedTypeTest.php index 01f19e01c4..e09fe8f7c0 100644 --- a/tests/PHPStan/Type/MixedTypeTest.php +++ b/tests/PHPStan/Type/MixedTypeTest.php @@ -13,6 +13,7 @@ use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class MixedTypeTest extends PHPStanTestCase @@ -159,9 +160,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(MixedType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -226,9 +225,7 @@ public static function dataSubstractedIsArray(): array ]; } - /** - * @dataProvider dataSubstractedIsArray - */ + #[DataProvider('dataSubstractedIsArray')] public function testSubstractedIsArray(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -300,9 +297,7 @@ public static function dataSubstractedIsConstantArray(): array ]; } - /** - * @dataProvider dataSubstractedIsConstantArray - */ + #[DataProvider('dataSubstractedIsConstantArray')] public function testSubstractedIsConstantArray(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -352,9 +347,7 @@ public static function dataSubstractedIsString(): array ]; } - /** - * @dataProvider dataSubstractedIsString - */ + #[DataProvider('dataSubstractedIsString')] public function testSubstractedIsString(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -404,9 +397,7 @@ public static function dataSubstractedIsNumericString(): array ]; } - /** - * @dataProvider dataSubstractedIsNumericString - */ + #[DataProvider('dataSubstractedIsNumericString')] public function testSubstractedIsNumericString(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -464,9 +455,7 @@ public static function dataSubstractedIsNonEmptyString(): array ]; } - /** - * @dataProvider dataSubstractedIsNonEmptyString - */ + #[DataProvider('dataSubstractedIsNonEmptyString')] public function testSubstractedIsNonEmptyString(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -524,9 +513,7 @@ public static function dataSubstractedIsNonFalsyString(): array ]; } - /** - * @dataProvider dataSubstractedIsNonFalsyString - */ + #[DataProvider('dataSubstractedIsNonFalsyString')] public function testSubstractedIsNonFalsyString(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -592,9 +579,7 @@ public static function dataSubstractedIsLiteralString(): array ]; } - /** - * @dataProvider dataSubstractedIsClassString - */ + #[DataProvider('dataSubstractedIsClassString')] public function testSubstractedIsClassString(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -636,7 +621,7 @@ public static function dataSubstractedIsClassString(): array ]; } - /** @dataProvider dataSubtractedIsVoid */ + #[DataProvider('dataSubtractedIsVoid')] public function testSubtractedIsVoid(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -665,7 +650,7 @@ public static function dataSubtractedIsVoid(): array ]; } - /** @dataProvider dataSubtractedIsScalar */ + #[DataProvider('dataSubtractedIsScalar')] public function testSubtractedIsScalar(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -694,9 +679,7 @@ public static function dataSubtractedIsScalar(): array ]; } - /** - * @dataProvider dataSubstractedIsLiteralString - */ + #[DataProvider('dataSubstractedIsLiteralString')] public function testSubstractedIsLiteralString(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -748,9 +731,7 @@ public static function dataSubstractedIsIterable(): array ]; } - /** - * @dataProvider dataSubstractedIsBoolean - */ + #[DataProvider('dataSubstractedIsBoolean')] public function testSubstractedIsBoolean(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -789,9 +770,7 @@ public static function dataSubstractedIsBoolean(): array ]; } - /** - * @dataProvider dataSubstractedIsFalse - */ + #[DataProvider('dataSubstractedIsFalse')] public function testSubstractedIsFalse(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -830,9 +809,7 @@ public static function dataSubstractedIsFalse(): array ]; } - /** - * @dataProvider dataSubstractedIsNull - */ + #[DataProvider('dataSubstractedIsNull')] public function testSubstractedIsNull(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -876,9 +853,7 @@ public static function dataSubstractedIsNull(): array ]; } - /** - * @dataProvider dataSubstractedIsTrue - */ + #[DataProvider('dataSubstractedIsTrue')] public function testSubstractedIsTrue(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -917,9 +892,7 @@ public static function dataSubstractedIsTrue(): array ]; } - /** - * @dataProvider dataSubstractedIsFloat - */ + #[DataProvider('dataSubstractedIsFloat')] public function testSubstractedIsFloat(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -953,9 +926,7 @@ public static function dataSubstractedIsFloat(): array ]; } - /** - * @dataProvider dataSubstractedIsInteger - */ + #[DataProvider('dataSubstractedIsInteger')] public function testSubstractedIsInteger(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -989,9 +960,7 @@ public static function dataSubstractedIsInteger(): array ]; } - /** - * @dataProvider dataSubstractedIsIterable - */ + #[DataProvider('dataSubstractedIsIterable')] public function testSubstractedIsIterable(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -1044,9 +1013,7 @@ public static function dataSubstractedIsOffsetAccessible(): array ]; } - /** - * @dataProvider dataSubstractedIsOffsetAccessible - */ + #[DataProvider('dataSubstractedIsOffsetAccessible')] public function testSubstractedIsOffsetAccessible(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -1091,9 +1058,7 @@ public static function dataSubstractedIsOffsetLegal(): array ]; } - /** - * @dataProvider dataSubstractedIsOffsetLegal - */ + #[DataProvider('dataSubstractedIsOffsetLegal')] public function testSubstractedIsOffsetLegal(MixedType $mixedType, Type $typeToSubtract, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); @@ -1151,7 +1116,7 @@ public static function dataSubtractedHasOffsetValueType(): array ]; } - /** @dataProvider dataSubtractedHasOffsetValueType */ + #[DataProvider('dataSubtractedHasOffsetValueType')] public function testSubtractedHasOffsetValueType(MixedType $mixedType, Type $typeToSubtract, Type $offsetType, TrinaryLogic $expectedResult): void { $subtracted = $mixedType->subtract($typeToSubtract); diff --git a/tests/PHPStan/Type/ObjectTypeTest.php b/tests/PHPStan/Type/ObjectTypeTest.php index 2babe378f4..fe9e864507 100644 --- a/tests/PHPStan/Type/ObjectTypeTest.php +++ b/tests/PHPStan/Type/ObjectTypeTest.php @@ -35,6 +35,8 @@ use PHPStan\Type\Generic\TemplateTypeScope; use PHPStan\Type\Generic\TemplateTypeVariance; use PHPStan\Type\Traits\ConstantNumericComparisonTypeTrait; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhp; use SimpleXMLElement; use stdClass; use Throwable; @@ -57,9 +59,7 @@ public static function dataIsIterable(): array ]; } - /** - * @dataProvider dataIsIterable - */ + #[DataProvider('dataIsIterable')] public function testIsIterable(ObjectType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isIterable(); @@ -86,9 +86,7 @@ public static function dataIsEnum(): iterable yield [new ObjectType('DateTime'), TrinaryLogic::createNo()]; } - /** - * @dataProvider dataIsEnum - */ + #[DataProvider('dataIsEnum')] public function testIsEnum(ObjectType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isEnum(); @@ -108,9 +106,7 @@ public static function dataIsCallable(): array ]; } - /** - * @dataProvider dataIsCallable - */ + #[DataProvider('dataIsCallable')] public function testIsCallable(ObjectType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isCallable(); @@ -485,9 +481,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(ObjectType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -549,9 +543,7 @@ public static function dataAccepts(): array ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts( ObjectType $type, Type $acceptedType, @@ -629,9 +621,7 @@ public static function dataHasOffsetValueType(): array ]; } - /** - * @dataProvider dataHasOffsetValueType - */ + #[DataProvider('dataHasOffsetValueType')] public function testHasOffsetValueType( ObjectType $type, Type $offsetType, @@ -678,18 +668,15 @@ public static function dataGetEnumCases(): iterable } /** - * @dataProvider dataGetEnumCases * @param list $expectedEnumCases */ + #[RequiresPhp('>= 8.1')] + #[DataProvider('dataGetEnumCases')] public function testGetEnumCases( ObjectType $type, array $expectedEnumCases, ): void { - if (PHP_VERSION_ID < 80100) { - $this->markTestSkipped('Test requires PHP 8.1.'); - } - $enumCases = $type->getEnumCases(); $this->assertCount(count($expectedEnumCases), $enumCases); foreach ($enumCases as $i => $enumCase) { diff --git a/tests/PHPStan/Type/ObjectWithoutClassTypeTest.php b/tests/PHPStan/Type/ObjectWithoutClassTypeTest.php index 3b3378cec0..69e33b253a 100644 --- a/tests/PHPStan/Type/ObjectWithoutClassTypeTest.php +++ b/tests/PHPStan/Type/ObjectWithoutClassTypeTest.php @@ -5,6 +5,7 @@ use InvalidArgumentException; use PHPStan\Testing\PHPStanTestCase; use PHPStan\TrinaryLogic; +use PHPUnit\Framework\Attributes\DataProvider; use function sprintf; class ObjectWithoutClassTypeTest extends PHPStanTestCase @@ -61,9 +62,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(ObjectWithoutClassType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); diff --git a/tests/PHPStan/Type/Regex/RegexExpressionHelperTest.php b/tests/PHPStan/Type/Regex/RegexExpressionHelperTest.php index 46498fda80..872ba25586 100644 --- a/tests/PHPStan/Type/Regex/RegexExpressionHelperTest.php +++ b/tests/PHPStan/Type/Regex/RegexExpressionHelperTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Type\Regex; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class RegexExpressionHelperTest extends PHPStanTestCase { @@ -45,9 +46,7 @@ public static function dataRemoveDelimitersAndModifiers(): array ]; } - /** - * @dataProvider dataRemoveDelimitersAndModifiers - */ + #[DataProvider('dataRemoveDelimitersAndModifiers')] public function testRemoveDelimitersAndModifiers(string $inputPattern, string $expectedPatternWithoutDelimiter): void { $regexExpressionHelper = self::getContainer()->getByType(RegexExpressionHelper::class); diff --git a/tests/PHPStan/Type/SimultaneousTypeTraverserTest.php b/tests/PHPStan/Type/SimultaneousTypeTraverserTest.php index 8161b624f9..f7be3c75f7 100644 --- a/tests/PHPStan/Type/SimultaneousTypeTraverserTest.php +++ b/tests/PHPStan/Type/SimultaneousTypeTraverserTest.php @@ -6,6 +6,7 @@ use PHPStan\Type\Accessory\AccessoryNonEmptyStringType; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantIntegerType; +use PHPUnit\Framework\Attributes\DataProvider; class SimultaneousTypeTraverserTest extends PHPStanTestCase { @@ -71,9 +72,7 @@ public static function dataChangeStringIntoNonEmptyString(): iterable ]; } - /** - * @dataProvider dataChangeStringIntoNonEmptyString - */ + #[DataProvider('dataChangeStringIntoNonEmptyString')] public function testChangeIntegerIntoString(Type $left, Type $right, string $expectedTypeDescription): void { $cb = static function (Type $left, Type $right, callable $traverse): Type { diff --git a/tests/PHPStan/Type/StaticTypeTest.php b/tests/PHPStan/Type/StaticTypeTest.php index bc9b80b0d6..980b5f6004 100644 --- a/tests/PHPStan/Type/StaticTypeTest.php +++ b/tests/PHPStan/Type/StaticTypeTest.php @@ -18,6 +18,7 @@ use PHPStan\Type\Generic\TemplateTypeFactory; use PHPStan\Type\Generic\TemplateTypeScope; use PHPStan\Type\Generic\TemplateTypeVariance; +use PHPUnit\Framework\Attributes\DataProvider; use StaticTypeTest\Base; use StaticTypeTest\Child; use StaticTypeTest\FinalChild; @@ -39,9 +40,7 @@ public static function dataIsIterable(): array ]; } - /** - * @dataProvider dataIsIterable - */ + #[DataProvider('dataIsIterable')] public function testIsIterable(StaticType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isIterable(); @@ -62,9 +61,7 @@ public static function dataIsCallable(): array ]; } - /** - * @dataProvider dataIsCallable - */ + #[DataProvider('dataIsCallable')] public function testIsCallable(StaticType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isCallable(); @@ -291,9 +288,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(Type $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -332,9 +327,7 @@ public static function dataEquals(): array ]; } - /** - * @dataProvider dataEquals - */ + #[DataProvider('dataEquals')] public function testEquals(StaticType $type, StaticType $otherType, bool $expected): void { $this->assertSame($expected, $type->equals($otherType)); @@ -455,9 +448,7 @@ public static function dataAccepts(): iterable ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts(StaticType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->accepts($otherType, true); diff --git a/tests/PHPStan/Type/StringTypeTest.php b/tests/PHPStan/Type/StringTypeTest.php index b31979633b..a5630c1a30 100644 --- a/tests/PHPStan/Type/StringTypeTest.php +++ b/tests/PHPStan/Type/StringTypeTest.php @@ -11,6 +11,7 @@ use PHPStan\Type\Generic\TemplateTypeFactory; use PHPStan\Type\Generic\TemplateTypeScope; use PHPStan\Type\Generic\TemplateTypeVariance; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use Test\ClassWithToString; use function sprintf; @@ -94,9 +95,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(StringType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -174,9 +173,7 @@ public static function dataAccepts(): iterable ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts(StringType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->accepts($otherType, true)->result; @@ -223,9 +220,7 @@ public static function dataEquals(): array ]; } - /** - * @dataProvider dataEquals - */ + #[DataProvider('dataEquals')] public function testEquals(StringType $type, Type $otherType, bool $expectedResult): void { $actualResult = $type->equals($otherType); diff --git a/tests/PHPStan/Type/TemplateTypeTest.php b/tests/PHPStan/Type/TemplateTypeTest.php index 4eead2fc37..61c8839f13 100644 --- a/tests/PHPStan/Type/TemplateTypeTest.php +++ b/tests/PHPStan/Type/TemplateTypeTest.php @@ -13,6 +13,7 @@ use PHPStan\Type\Generic\TemplateTypeHelper; use PHPStan\Type\Generic\TemplateTypeScope; use PHPStan\Type\Generic\TemplateTypeVariance; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use Throwable; use Traversable; @@ -96,9 +97,7 @@ public static function dataAccepts(): array ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts( Type $type, Type $otherType, @@ -285,9 +284,7 @@ public static function dataIsSuperTypeOf(): array ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf( Type $type, Type $otherType, @@ -361,9 +358,9 @@ public static function dataInferTemplateTypes(): array } /** - * @dataProvider dataInferTemplateTypes * @param array $expectedTypes */ + #[DataProvider('dataInferTemplateTypes')] public function testResolveTemplateTypes(Type $received, Type $template, array $expectedTypes): void { $result = $template->inferTemplateTypes($received); diff --git a/tests/PHPStan/Type/TestDecimalOperatorTypeSpecifyingExtensionTest.php b/tests/PHPStan/Type/TestDecimalOperatorTypeSpecifyingExtensionTest.php index 88aca2ce8c..822844c0e2 100644 --- a/tests/PHPStan/Type/TestDecimalOperatorTypeSpecifyingExtensionTest.php +++ b/tests/PHPStan/Type/TestDecimalOperatorTypeSpecifyingExtensionTest.php @@ -3,15 +3,14 @@ namespace PHPStan\Type; use PHPStan\Fixture\TestDecimal; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use stdClass; class TestDecimalOperatorTypeSpecifyingExtensionTest extends TestCase { - /** - * @dataProvider dataSigilAndSidesProvider - */ + #[DataProvider('dataSigilAndSidesProvider')] public function testSupportsMatchingSigilsAndSides(string $sigil, Type $leftType, Type $rightType): void { $extension = new TestDecimalOperatorTypeSpecifyingExtension(); @@ -60,9 +59,7 @@ public static function dataSigilAndSidesProvider(): iterable ]; } - /** - * @dataProvider dataNotMatchingSidesProvider - */ + #[DataProvider('dataNotMatchingSidesProvider')] public function testNotSupportsNotMatchingSides(string $sigil, Type $leftType, Type $rightType): void { $extension = new TestDecimalOperatorTypeSpecifyingExtension(); diff --git a/tests/PHPStan/Type/TypeCombinatorTest.php b/tests/PHPStan/Type/TypeCombinatorTest.php index 92a320363d..6a8a87d0c4 100644 --- a/tests/PHPStan/Type/TypeCombinatorTest.php +++ b/tests/PHPStan/Type/TypeCombinatorTest.php @@ -48,6 +48,7 @@ use PHPStan\Type\Generic\TemplateTypeFactory; use PHPStan\Type\Generic\TemplateTypeScope; use PHPStan\Type\Generic\TemplateTypeVariance; +use PHPUnit\Framework\Attributes\DataProvider; use RecursionCallable\Foo; use stdClass; use Test\ClassWithNullableProperty; @@ -128,9 +129,9 @@ public static function dataAddNull(): array } /** - * @dataProvider dataAddNull * @param class-string $expectedTypeClass */ + #[DataProvider('dataAddNull')] public function testAddNull( Type $type, string $expectedTypeClass, @@ -143,9 +144,9 @@ public function testAddNull( } /** - * @dataProvider dataAddNull * @param class-string $expectedTypeClass */ + #[DataProvider('dataAddNull')] public function testUnionWithNull( Type $type, string $expectedTypeClass, @@ -246,9 +247,9 @@ public static function dataRemoveNull(): array } /** - * @dataProvider dataRemoveNull * @param class-string $expectedTypeClass */ + #[DataProvider('dataRemoveNull')] public function testRemoveNull( Type $type, string $expectedTypeClass, @@ -2796,10 +2797,10 @@ public static function dataUnion(): iterable } /** - * @dataProvider dataUnion * @param Type[] $types * @param class-string $expectedTypeClass */ + #[DataProvider('dataUnion')] public function testUnion( array $types, string $expectedTypeClass, @@ -2852,10 +2853,10 @@ public function testUnion( } /** - * @dataProvider dataUnion * @param Type[] $types * @param class-string $expectedTypeClass */ + #[DataProvider('dataUnion')] public function testUnionInversed( array $types, string $expectedTypeClass, @@ -4727,10 +4728,10 @@ public static function dataIntersect(): iterable } /** - * @dataProvider dataIntersect * @param Type[] $types * @param class-string $expectedTypeClass */ + #[DataProvider('dataIntersect')] public function testIntersect( array $types, string $expectedTypeClass, @@ -4770,10 +4771,10 @@ public function testIntersect( } /** - * @dataProvider dataIntersect * @param Type[] $types * @param class-string $expectedTypeClass */ + #[DataProvider('dataIntersect')] public function testIntersectInversed( array $types, string $expectedTypeClass, @@ -5310,9 +5311,9 @@ public static function dataRemove(): array } /** - * @dataProvider dataRemove * @param class-string $expectedTypeClass */ + #[DataProvider('dataRemove')] public function testRemove( Type $fromType, Type $type, @@ -5352,9 +5353,7 @@ public function testSpecificUnionConstantArray(): void $this->assertSame('array{0: string, 1?: string, 2?: string, 3?: string, 4?: string, test?: string}', $resultType->describe(VerbosityLevel::precise())); } - /** - * @dataProvider dataContainsNull - */ + #[DataProvider('dataContainsNull')] public function testContainsNull( Type $type, bool $expectedResult, diff --git a/tests/PHPStan/Type/TypeGetFiniteTypesTest.php b/tests/PHPStan/Type/TypeGetFiniteTypesTest.php index d64e96e047..e7e0ae2de6 100644 --- a/tests/PHPStan/Type/TypeGetFiniteTypesTest.php +++ b/tests/PHPStan/Type/TypeGetFiniteTypesTest.php @@ -10,6 +10,7 @@ use PHPStan\Type\Generic\TemplateTypeFactory; use PHPStan\Type\Generic\TemplateTypeScope; use PHPStan\Type\Generic\TemplateTypeVariance; +use PHPUnit\Framework\Attributes\DataProvider; class TypeGetFiniteTypesTest extends PHPStanTestCase { @@ -124,9 +125,9 @@ public static function dataGetFiniteTypes(): iterable } /** - * @dataProvider dataGetFiniteTypes * @param list $expectedTypes */ + #[DataProvider('dataGetFiniteTypes')] public function testGetFiniteTypes( Type $type, array $expectedTypes, diff --git a/tests/PHPStan/Type/TypeToPhpDocNodeTest.php b/tests/PHPStan/Type/TypeToPhpDocNodeTest.php index 95103ab3fb..29bfe8f70a 100644 --- a/tests/PHPStan/Type/TypeToPhpDocNodeTest.php +++ b/tests/PHPStan/Type/TypeToPhpDocNodeTest.php @@ -20,6 +20,7 @@ use PHPStan\Type\Generic\GenericClassStringType; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\Generic\TemplateTypeVariance; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use function sprintf; use const PHP_INT_MAX; @@ -434,9 +435,7 @@ public static function dataToPhpDocNode(): iterable ]; } - /** - * @dataProvider dataToPhpDocNode - */ + #[DataProvider('dataToPhpDocNode')] public function testToPhpDocNode(Type $type, string $expected): void { $phpDocNode = $type->toPhpDocNode(); @@ -517,9 +516,7 @@ public static function dataToPhpDocNodeWithoutCheckingEquals(): iterable ]; } - /** - * @dataProvider dataToPhpDocNodeWithoutCheckingEquals - */ + #[DataProvider('dataToPhpDocNodeWithoutCheckingEquals')] public function testToPhpDocNodeWithoutCheckingEquals(Type $type, string $expected): void { $phpDocNode = $type->toPhpDocNode(); @@ -548,9 +545,7 @@ public static function dataFromTypeStringToPhpDocNode(): iterable yield ['Closure(Foo $foo=, Bar $bar=): (Closure(Foo): Bar)']; } - /** - * @dataProvider dataFromTypeStringToPhpDocNode - */ + #[DataProvider('dataFromTypeStringToPhpDocNode')] public function testFromTypeStringToPhpDocNode(string $typeString): void { $typeStringResolver = self::getContainer()->getByType(TypeStringResolver::class); diff --git a/tests/PHPStan/Type/UnionTypeTest.php b/tests/PHPStan/Type/UnionTypeTest.php index 0de9040ff0..fc61301a2f 100644 --- a/tests/PHPStan/Type/UnionTypeTest.php +++ b/tests/PHPStan/Type/UnionTypeTest.php @@ -27,6 +27,7 @@ use PHPStan\Type\Generic\TemplateTypeFactory; use PHPStan\Type\Generic\TemplateTypeScope; use PHPStan\Type\Generic\TemplateTypeVariance; +use PHPUnit\Framework\Attributes\DataProvider; use RecursionCallable\Foo; use stdClass; use function array_merge; @@ -75,9 +76,7 @@ public static function dataIsCallable(): array ]; } - /** - * @dataProvider dataIsCallable - */ + #[DataProvider('dataIsCallable')] public function testIsCallable(UnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isCallable(); @@ -147,10 +146,7 @@ public static function dataSelfCompare(): Iterator yield [new VoidType()]; } - /** - * @dataProvider dataSelfCompare - * - */ + #[DataProvider('dataSelfCompare')] public function testSelfCompare(Type $type): void { $description = $type->describe(VerbosityLevel::precise()); @@ -453,9 +449,7 @@ public static function dataIsSuperTypeOf(): Iterator ]; } - /** - * @dataProvider dataIsSuperTypeOf - */ + #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(UnionType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSuperTypeOf($otherType); @@ -621,9 +615,7 @@ public static function dataIsSubTypeOf(): Iterator ]; } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOf(UnionType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->isSubTypeOf($otherType); @@ -634,9 +626,7 @@ public function testIsSubTypeOf(UnionType $type, Type $otherType, TrinaryLogic $ ); } - /** - * @dataProvider dataIsSubTypeOf - */ + #[DataProvider('dataIsSubTypeOf')] public function testIsSubTypeOfInversed(UnionType $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $otherType->isSuperTypeOf($type); @@ -699,7 +689,7 @@ public static function dataIsScalar(): array ]; } - /** @dataProvider dataIsScalar */ + #[DataProvider('dataIsScalar')] public function testIsScalar(UnionType $type, TrinaryLogic $expectedResult): void { $actualResult = $type->isScalar(); @@ -938,9 +928,7 @@ public static function dataDescribe(): array ]; } - /** - * @dataProvider dataDescribe - */ + #[DataProvider('dataDescribe')] public function testDescribe( Type $type, string $expectedPreciseDescription, @@ -1294,9 +1282,7 @@ public static function dataAccepts(): iterable ]; } - /** - * @dataProvider dataAccepts - */ + #[DataProvider('dataAccepts')] public function testAccepts( UnionType $type, Type $acceptedType, @@ -1336,9 +1322,7 @@ public static function dataHasMethod(): array ]; } - /** - * @dataProvider dataHasMethod - */ + #[DataProvider('dataHasMethod')] public function testHasMethod( UnionType $type, string $methodName, @@ -1389,10 +1373,10 @@ public function testSorting(): void } /** - * @dataProvider dataGetConstantArrays * @param Type[] $types * @param list $expectedDescriptions */ + #[DataProvider('dataGetConstantArrays')] public function testGetConstantArrays( array $types, array $expectedDescriptions, @@ -1452,9 +1436,9 @@ public static function dataGetConstantArrays(): iterable } /** - * @dataProvider dataGetConstantStrings * @param list $expectedDescriptions */ + #[DataProvider('dataGetConstantStrings')] public function testGetConstantStrings( Type $unionType, array $expectedDescriptions, @@ -1526,9 +1510,9 @@ public static function dataGetConstantStrings(): iterable } /** - * @dataProvider dataGetObjectClassNames * @param list $expectedObjectClassNames */ + #[DataProvider('dataGetObjectClassNames')] public function testGetObjectClassNames( Type $unionType, array $expectedObjectClassNames, @@ -1568,9 +1552,9 @@ public static function dataGetObjectClassNames(): iterable } /** - * @dataProvider dataGetArrays * @param list $expectedDescriptions */ + #[DataProvider('dataGetArrays')] public function testGetArrays( Type $unionType, array $expectedDescriptions, diff --git a/tests/PHPStan/Type/VerbosityLevelTest.php b/tests/PHPStan/Type/VerbosityLevelTest.php index af663b59cf..5297e6505f 100644 --- a/tests/PHPStan/Type/VerbosityLevelTest.php +++ b/tests/PHPStan/Type/VerbosityLevelTest.php @@ -7,6 +7,7 @@ use PHPStan\Type\Accessory\AccessoryNonFalsyStringType; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\Generic\TemplateTypeVariance; +use PHPUnit\Framework\Attributes\DataProvider; class VerbosityLevelTest extends PHPStanTestCase { @@ -44,9 +45,7 @@ public static function dataGetRecommendedLevelByType(): iterable ]; } - /** - * @dataProvider dataGetRecommendedLevelByType - */ + #[DataProvider('dataGetRecommendedLevelByType')] public function testGetRecommendedLevelByType(Type $acceptingType, ?Type $acceptedType, VerbosityLevel $expected): void { $level = VerbosityLevel::getRecommendedLevelByType($acceptingType, $acceptedType);