Skip to content

Commit e1bfd76

Browse files
authored
Deprecate ReplaceTestFunctionPrefixWithAttributeRector (#739)
1 parent 9f7ae4a commit e1bfd76

7 files changed

Lines changed: 8 additions & 173 deletions

File tree

‎phpstan.neon‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,3 @@ parameters:
4343
# see https://github.com/rectorphp/rector-src/actions/runs/11798721617/job/32865546672?pr=6422#step:5:110
4444
- '#Doing instanceof PHPStan\\Type\\.+ is error\-prone and deprecated#'
4545

46-
# false positive
47-
-
48-
identifier: assign.propertyType
49-
message: '#Property PhpParser\\Node\\Identifier\:\:\$name \(non\-empty\-string\) does not accept string#'
50-
path: rules/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector.php
51-

‎rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_camelCase.php.inc‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_just_test_name.php.inc‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/Fixture/fixture_snake_case.php.inc‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/ReplaceTestFunctionPrefixWithAttributeRectorTest.php‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎rules-tests/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector/config/configured_rule.php‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎rules/CodeQuality/Rector/ClassMethod/ReplaceTestFunctionPrefixWithAttributeRector.php‎

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,18 @@
55
namespace Rector\PHPUnit\CodeQuality\Rector\ClassMethod;
66

77
use PhpParser\Node;
8-
use PhpParser\Node\AttributeGroup;
98
use PhpParser\Node\Stmt\ClassMethod;
10-
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
11-
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
12-
use Rector\PHPUnit\Enum\PHPUnitAttribute;
13-
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
9+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
10+
use Rector\Exception\ShouldNotHappenException;
1411
use Rector\Rector\AbstractRector;
1512
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1613
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1714

1815
/**
19-
* @see \Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector\ReplaceTestAnnotationWithPrefixedFunctionRectorTest
16+
* @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.
2017
*/
21-
final class ReplaceTestFunctionPrefixWithAttributeRector extends AbstractRector
18+
final class ReplaceTestFunctionPrefixWithAttributeRector extends AbstractRector implements DeprecatedInterface
2219
{
23-
public function __construct(
24-
private readonly TestsNodeAnalyzer $testsNodeAnalyzer,
25-
private readonly PhpAttributeGroupFactory $phpAttributeGroupFactory,
26-
private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer,
27-
) {
28-
}
29-
3020
public function getRuleDefinition(): RuleDefinition
3121
{
3222
return new RuleDefinition('Replace @test with prefixed function', [
@@ -68,36 +58,9 @@ public function getNodeTypes(): array
6858
*/
6959
public function refactor(Node $node): ?Node
7060
{
71-
if (! $this->testsNodeAnalyzer->isInTestClass($node)) {
72-
return null;
73-
}
74-
75-
if (! str_starts_with($node->name->toString(), 'test')) {
76-
return null;
77-
}
78-
79-
if ($this->phpAttributeAnalyzer->hasPhpAttributes($node, [PHPUnitAttribute::TEST])) {
80-
return null;
81-
}
82-
83-
if ($node->name->toString() !== 'test' && $node->name->toString() !== 'test_') {
84-
if (str_starts_with($node->name->toString(), 'test_')) {
85-
$node->name->name = lcfirst(substr($node->name->name, 5));
86-
} elseif (str_starts_with($node->name->toString(), 'test')) {
87-
$node->name->name = lcfirst(substr($node->name->name, 4));
88-
}
89-
}
90-
91-
$coversAttributeGroup = $this->createAttributeGroup();
92-
$node->attrGroups = array_merge($node->attrGroups, [$coversAttributeGroup]);
93-
94-
return $node;
95-
}
96-
97-
private function createAttributeGroup(): AttributeGroup
98-
{
99-
$attributeClass = 'PHPUnit\\Framework\\Attributes\\Test';
100-
101-
return $this->phpAttributeGroupFactory->createFromClassWithItems($attributeClass, []);
61+
throw new ShouldNotHappenException(sprintf(
62+
'"%s" is deprecated and should not be used anymore. Remove it from your config files.',
63+
self::class,
64+
));
10265
}
10366
}

0 commit comments

Comments
 (0)