Skip to content

Commit 6a02976

Browse files
committed
fix
1 parent a9324ed commit 6a02976

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

rules/CodeQuality/Rector/ClassMethod/NoSetupWithParentCallOverrideRector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Rector\PHPUnit\CodeQuality\NodeAnalyser\ParentCallDetector;
1111
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
1212
use Rector\Rector\AbstractRector;
13+
use Rector\Reflection\ReflectionResolver;
1314
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1415
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1516

@@ -22,6 +23,7 @@ public function __construct(
2223
private readonly TestsNodeAnalyzer $testsNodeAnalyzer,
2324
private readonly ParentCallDetector $parentCallDetector,
2425
private readonly AttributeFinder $attributeFinder,
26+
private readonly ReflectionResolver $reflectionResolver,
2527
) {
2628
}
2729

@@ -78,7 +80,7 @@ public function getNodeTypes(): array
7880
*/
7981
public function refactor(Node $node): ?Node
8082
{
81-
if (! $this->testsNodeAnalyzer->isInTestClass($node)) {
83+
if (! $this->testsNodeAnalyzer->isDirectlyExtendsTestCase($node)) {
8284
return null;
8385
}
8486

src/NodeAnalyzer/TestsNodeAnalyzer.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ public function isInTestClass(Node $node): bool
4343
return false;
4444
}
4545

46+
public function isDirectlyExtendsTestCase(Node $node): bool
47+
{
48+
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
49+
if (! $classReflection instanceof ClassReflection) {
50+
return false;
51+
}
52+
53+
$parents = $classReflection->getParents();
54+
if ($parents === []) {
55+
return false;
56+
}
57+
58+
foreach (PHPUnitClassName::TEST_CLASSES as $testCaseObjectClass) {
59+
if ($parents[0]->getName() === $testCaseObjectClass) {
60+
return true;
61+
}
62+
}
63+
64+
return false;
65+
}
66+
4667
public function isTestClassMethod(ClassMethod $classMethod): bool
4768
{
4869
if (! $classMethod->isPublic()) {

0 commit comments

Comments
 (0)