From 2637cfd1df6be0f8a1fbb9dd48a9d38c4283f3c1 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 31 Jul 2026 13:18:47 +0200 Subject: [PATCH] Deprecate ReplaceTestFunctionPrefixWithAttributeRector --- phpstan.neon | 6 --- .../Fixture/fixture_camelCase.php.inc | 28 ---------- .../Fixture/fixture_just_test_name.php.inc | 28 ---------- .../Fixture/fixture_snake_case.php.inc | 28 ---------- ...tFunctionPrefixWithAttributeRectorTest.php | 28 ---------- .../config/configured_rule.php | 10 ---- ...eTestFunctionPrefixWithAttributeRector.php | 53 +++---------------- 7 files changed, 8 insertions(+), 173 deletions(-) delete mode 100644 rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_camelCase.php.inc delete mode 100644 rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_just_test_name.php.inc delete mode 100644 rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_snake_case.php.inc delete mode 100644 rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/ReplaceTestFunctionPrefixWithAttributeRectorTest.php delete mode 100644 rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/config/configured_rule.php diff --git a/phpstan.neon b/phpstan.neon index ff2e4fe3..5bc84d63 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -43,9 +43,3 @@ parameters: # see https://github.com/rectorphp/rector-src/actions/runs/11798721617/job/32865546672?pr=6422#step:5:110 - '#Doing instanceof PHPStan\\Type\\.+ is error\-prone and deprecated#' - # false positive - - - identifier: assign.propertyType - message: '#Property PhpParser\\Node\\Identifier\:\:\$name \(non\-empty\-string\) does not accept string#' - path: rules/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector.php - diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_camelCase.php.inc b/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_camelCase.php.inc deleted file mode 100644 index ddfba7e8..00000000 --- a/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_camelCase.php.inc +++ /dev/null @@ -1,28 +0,0 @@ -assertSame(2, 1+1); - } -} - -?> ------ -assertSame(2, 1+1); - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_just_test_name.php.inc b/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_just_test_name.php.inc deleted file mode 100644 index 18ac5fd4..00000000 --- a/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_just_test_name.php.inc +++ /dev/null @@ -1,28 +0,0 @@ -assertSame(2, 1+1); - } -} - -?> ------ -assertSame(2, 1+1); - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_snake_case.php.inc b/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_snake_case.php.inc deleted file mode 100644 index 7f1948a6..00000000 --- a/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_snake_case.php.inc +++ /dev/null @@ -1,28 +0,0 @@ -assertSame(2, 1+1); - } -} - -?> ------ -assertSame(2, 1+1); - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/ReplaceTestFunctionPrefixWithAttributeRectorTest.php b/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/ReplaceTestFunctionPrefixWithAttributeRectorTest.php deleted file mode 100644 index 487abf75..00000000 --- a/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/ReplaceTestFunctionPrefixWithAttributeRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/config/configured_rule.php b/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/config/configured_rule.php deleted file mode 100644 index a8f72f4d..00000000 --- a/rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(ReplaceTestFunctionPrefixWithAttributeRector::class); -}; diff --git a/rules/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector.php b/rules/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector.php index 2fb782c7..9cfe8a98 100644 --- a/rules/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector.php +++ b/rules/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector.php @@ -5,28 +5,18 @@ namespace Rector\PHPUnit\CodeQuality\Rector\ClassMethod; use PhpParser\Node; -use PhpParser\Node\AttributeGroup; use PhpParser\Node\Stmt\ClassMethod; -use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; -use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory; -use Rector\PHPUnit\Enum\PHPUnitAttribute; -use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector\ReplaceTestAnnotationWithPrefixedFunctionRectorTest + * @deprecated This rule is deprecated as it is not a common upgrade path and it is not part of any set. Implement it as a custom rule instead. */ -final class ReplaceTestFunctionPrefixWithAttributeRector extends AbstractRector +final class ReplaceTestFunctionPrefixWithAttributeRector extends AbstractRector implements DeprecatedInterface { - public function __construct( - private readonly TestsNodeAnalyzer $testsNodeAnalyzer, - private readonly PhpAttributeGroupFactory $phpAttributeGroupFactory, - private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer, - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Replace @test with prefixed function', [ @@ -68,36 +58,9 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if (! $this->testsNodeAnalyzer->isInTestClass($node)) { - return null; - } - - if (! str_starts_with($node->name->toString(), 'test')) { - return null; - } - - if ($this->phpAttributeAnalyzer->hasPhpAttributes($node, [PHPUnitAttribute::TEST])) { - return null; - } - - if ($node->name->toString() !== 'test' && $node->name->toString() !== 'test_') { - if (str_starts_with($node->name->toString(), 'test_')) { - $node->name->name = lcfirst(substr($node->name->name, 5)); - } elseif (str_starts_with($node->name->toString(), 'test')) { - $node->name->name = lcfirst(substr($node->name->name, 4)); - } - } - - $coversAttributeGroup = $this->createAttributeGroup(); - $node->attrGroups = array_merge($node->attrGroups, [$coversAttributeGroup]); - - return $node; - } - - private function createAttributeGroup(): AttributeGroup - { - $attributeClass = 'PHPUnit\\Framework\\Attributes\\Test'; - - return $this->phpAttributeGroupFactory->createFromClassWithItems($attributeClass, []); + throw new ShouldNotHappenException(sprintf( + '"%s" is deprecated and should not be used anymore. Remove it from your config files.', + self::class, + )); } }