From 104dc95b18b6024a25dd944cae4fef1453687022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=A0pa=C4=8Dek?= Date: Tue, 19 Mar 2024 02:36:39 +0100 Subject: [PATCH] Add attributes in addition to docblocks Added in PHPUnit 10, in 11 docblocks with no attributes throw something like 3) Metadata found in doc-comment for method Spaze\PHPStan\Rules\Disallowed\Identifier\IdentifierTest::testMatches(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. --- composer.json | 2 +- tests/Allowed/AllowedPathTest.php | 2 ++ tests/Calls/FunctionCallsNamedParamsTest.php | 2 ++ tests/DisallowedSuperglobalFactoryTest.php | 2 ++ tests/File/FilePathTest.php | 2 ++ tests/Identifier/IdentifierTest.php | 3 +++ tests/Usages/ClassConstantEnumUsagesTest.php | 2 ++ tests/Usages/NamespaceUsagesTypesTest.php | 2 ++ 8 files changed, 16 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 05405e4..66164ef 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "require-dev": { "nette/neon": "^3.2", "nikic/php-parser": "^4.13 || ^5.0", - "phpunit/phpunit": "^8.5 || ^10.1", + "phpunit/phpunit": "^8.5 || ^10.1 || ^11.0", "php-parallel-lint/php-parallel-lint": "^1.2", "php-parallel-lint/php-console-highlighter": "^1.0", "spaze/coding-standard": "^1.7" diff --git a/tests/Allowed/AllowedPathTest.php b/tests/Allowed/AllowedPathTest.php index 34e7202..92c18d7 100644 --- a/tests/Allowed/AllowedPathTest.php +++ b/tests/Allowed/AllowedPathTest.php @@ -11,6 +11,7 @@ use PHPStan\Reflection\ReflectionProvider; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use Spaze\PHPStan\Rules\Disallowed\File\FilePath; use Traits\TestClass; use Traits\TestTrait; @@ -44,6 +45,7 @@ protected function setUp(): void /** * @dataProvider pathProvider */ + #[DataProvider('pathProvider')] public function testMatches(string $allowedPath, string $file, string $fileWithRootDir): void { $context = ScopeContext::create($file); diff --git a/tests/Calls/FunctionCallsNamedParamsTest.php b/tests/Calls/FunctionCallsNamedParamsTest.php index c163910..b25fea4 100644 --- a/tests/Calls/FunctionCallsNamedParamsTest.php +++ b/tests/Calls/FunctionCallsNamedParamsTest.php @@ -6,12 +6,14 @@ use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; /** * @requires PHP >= 8.0 */ +#[RequiresPhp('>= 8.0')] class FunctionCallsNamedParamsTest extends RuleTestCase { diff --git a/tests/DisallowedSuperglobalFactoryTest.php b/tests/DisallowedSuperglobalFactoryTest.php index 624990c..4ab9425 100644 --- a/tests/DisallowedSuperglobalFactoryTest.php +++ b/tests/DisallowedSuperglobalFactoryTest.php @@ -6,6 +6,7 @@ use Generator; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class DisallowedSuperglobalFactoryTest extends PHPStanTestCase { @@ -16,6 +17,7 @@ class DisallowedSuperglobalFactoryTest extends PHPStanTestCase * @param class-string|null $exceptionClass * @throws ShouldNotHappenException */ + #[DataProvider('superglobalsProvider')] public function testNonSuperglobalInConfig(string $superglobal, ?string $exceptionClass) { if ($exceptionClass) { diff --git a/tests/File/FilePathTest.php b/tests/File/FilePathTest.php index b06926a..08e2e26 100644 --- a/tests/File/FilePathTest.php +++ b/tests/File/FilePathTest.php @@ -6,6 +6,7 @@ use Generator; use PHPStan\File\FileHelper; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class FilePathTest extends PHPStanTestCase { @@ -28,6 +29,7 @@ protected function setUp(): void /** * @dataProvider pathProvider */ + #[DataProvider('pathProvider')] public function testFnMatch(string $path, string $file, string $fileWithRootDir): void { $this->assertTrue($this->filePath->fnMatch($path, $file)); diff --git a/tests/Identifier/IdentifierTest.php b/tests/Identifier/IdentifierTest.php index 00b4f6a..90209bd 100644 --- a/tests/Identifier/IdentifierTest.php +++ b/tests/Identifier/IdentifierTest.php @@ -5,6 +5,7 @@ use Generator; use PHPStan\Testing\PHPStanTestCase; +use PHPUnit\Framework\Attributes\DataProvider; class IdentifierTest extends PHPStanTestCase { @@ -26,6 +27,7 @@ protected function setUp(): void * @return void * @dataProvider matchesProvider */ + #[DataProvider('matchesProvider')] public function testMatches(string $pattern, string $value, ?array $excludes): void { $this->assertTrue($this->identifier->matches($pattern, $value, $excludes)); @@ -39,6 +41,7 @@ public function testMatches(string $pattern, string $value, ?array $excludes): v * @return void * @dataProvider doesNotMatchProvider */ + #[DataProvider('doesNotMatchProvider')] public function testDoesNotMatch(string $pattern, string $value, ?array $excludes): void { $this->assertFalse($this->identifier->matches($pattern, $value, $excludes)); diff --git a/tests/Usages/ClassConstantEnumUsagesTest.php b/tests/Usages/ClassConstantEnumUsagesTest.php index a7dc55c..93f3708 100644 --- a/tests/Usages/ClassConstantEnumUsagesTest.php +++ b/tests/Usages/ClassConstantEnumUsagesTest.php @@ -7,6 +7,7 @@ use Enums\Enum; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use Spaze\PHPStan\Rules\Disallowed\DisallowedConstantFactory; use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedConstantRuleErrors; @@ -15,6 +16,7 @@ /** * @requires PHP >= 8.1 */ +#[RequiresPhp('>= 8.1')] class ClassConstantEnumUsagesTest extends RuleTestCase { diff --git a/tests/Usages/NamespaceUsagesTypesTest.php b/tests/Usages/NamespaceUsagesTypesTest.php index 84f614e..827ee56 100644 --- a/tests/Usages/NamespaceUsagesTypesTest.php +++ b/tests/Usages/NamespaceUsagesTypesTest.php @@ -5,6 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use PHPUnit\Framework\Attributes\RequiresPhp; use Spaze\PHPStan\Rules\Disallowed\DisallowedNamespaceFactory; use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedNamespaceRuleErrors; @@ -12,6 +13,7 @@ /** * @requires PHP >= 8.1 */ +#[RequiresPhp('>= 8.1')] class NamespaceUsagesTypesTest extends RuleTestCase {