Skip to content

Commit

Permalink
Fix logic in ShouldCallParentMethodsRule
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 29, 2020
1 parent 20f23c9 commit 264abf4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Rules/PHPUnit/ShouldCallParentMethodsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function getNodeType(): string

public function processNode(Node $node, Scope $scope): array
{
$methodName = $node->getOriginalNode()->name->name;
if (!in_array(strtolower($methodName), ['setup', 'teardown'], true)) {
return [];
}
if ($scope->getClassReflection() === null) {
return [];
}
Expand All @@ -34,14 +38,12 @@ public function processNode(Node $node, Scope $scope): array
if ($parentClass === false) {
return [];
}

if ($parentClass->getName() === TestCase::class) {
if (!$parentClass->hasNativeMethod($methodName)) {
return [];
}

$methodName = $node->getOriginalNode()->name->name;

if (!in_array(strtolower($methodName), ['setup', 'teardown'], true)) {
$parentMethod = $parentClass->getNativeMethod($methodName);
if ($parentMethod->getDeclaringClass()->getName() === TestCase::class) {
return [];
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Rules/PHPUnit/data/missing-parent-method-calls.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,18 @@ public function setUp()
return true;
}
}

abstract class BaseTestWithoutSetUp extends TestCase
{

}

class LoremTest extends BaseTestWithoutSetUp
{

protected function setUp(): void
{
// parent call is not missing here
}

}

0 comments on commit 264abf4

Please sign in to comment.