Skip to content

Commit 264abf4

Browse files
committed
Fix logic in ShouldCallParentMethodsRule
1 parent 20f23c9 commit 264abf4

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/Rules/PHPUnit/ShouldCallParentMethodsRule.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public function getNodeType(): string
2121

2222
public function processNode(Node $node, Scope $scope): array
2323
{
24+
$methodName = $node->getOriginalNode()->name->name;
25+
if (!in_array(strtolower($methodName), ['setup', 'teardown'], true)) {
26+
return [];
27+
}
2428
if ($scope->getClassReflection() === null) {
2529
return [];
2630
}
@@ -34,14 +38,12 @@ public function processNode(Node $node, Scope $scope): array
3438
if ($parentClass === false) {
3539
return [];
3640
}
37-
38-
if ($parentClass->getName() === TestCase::class) {
41+
if (!$parentClass->hasNativeMethod($methodName)) {
3942
return [];
4043
}
4144

42-
$methodName = $node->getOriginalNode()->name->name;
43-
44-
if (!in_array(strtolower($methodName), ['setup', 'teardown'], true)) {
45+
$parentMethod = $parentClass->getNativeMethod($methodName);
46+
if ($parentMethod->getDeclaringClass()->getName() === TestCase::class) {
4547
return [];
4648
}
4749

tests/Rules/PHPUnit/data/missing-parent-method-calls.php

+15
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,18 @@ public function setUp()
7575
return true;
7676
}
7777
}
78+
79+
abstract class BaseTestWithoutSetUp extends TestCase
80+
{
81+
82+
}
83+
84+
class LoremTest extends BaseTestWithoutSetUp
85+
{
86+
87+
protected function setUp(): void
88+
{
89+
// parent call is not missing here
90+
}
91+
92+
}

0 commit comments

Comments
 (0)