Skip to content

Commit

Permalink
Merge 1736a9d into eb86811
Browse files Browse the repository at this point in the history
  • Loading branch information
ikvasnica committed Aug 9, 2020
2 parents eb86811 + 1736a9d commit 04537dc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Rules/Helpers/CallToAssertDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPUnit\Framework\TestCase;
use function strtolower;

final class CallToAssertDetector
{
Expand All @@ -17,11 +18,17 @@ public static function isCallToAssert(Node $node, Scope $scope): bool
return false;
}

if ($scope->getClassReflection() === null || $scope->getClassReflection()->getAncestorWithClassName(TestCase::class) === null) {
if ($scope->getClassReflection() === null) {
return false;
}

$phpUnitTestCaseAncestor = $scope->getClassReflection()->getAncestorWithClassName(TestCase::class);
if ($phpUnitTestCaseAncestor === null) {
return false;
}

return $node->name instanceof Node\Identifier
&& $phpUnitTestCaseAncestor->hasMethod($node->name->toString())
&& Strings::startsWith(strtolower($node->name->toString()), 'assert');
}
}
5 changes: 4 additions & 1 deletion tests/Rules/data/dummy-test-case.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@

abstract class DummyTestCase extends TestCase
{

protected static function assertSomethingSpecial(): void
{
// intentionally does nothing
}
}
9 changes: 9 additions & 0 deletions tests/Rules/data/static-assert-over-this-and-static-rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@ public function dummyTest(): void
Assert::assertCount(1, [1, 2]);
Assert::assertTrue(false);
\PHPUnit\Framework\Assert::assertTrue(true);
$this->assertCustomPrivateMethod();
static::assertCustomPrivateMethod();
$this->assertSomethingSpecial();
static::assertSomethingSpecial();
}

private function assertCustomPrivateMethod(): void
{
// intentionally does nothing
}
}

0 comments on commit 04537dc

Please sign in to comment.