Skip to content

Commit

Permalink
Ignore abstract classes in strict mocking PHPStan rule (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-challis authored Dec 2, 2023
1 parent 8e678d7 commit 994f17d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Phpstan/Rule/EnforceStrictMocking.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

if ($node->isAbstract()) {
return [];
}

$className = $node->namespacedName->toString();
if (!\str_ends_with($className, 'Test')) {
return [];
Expand Down
6 changes: 6 additions & 0 deletions tests/phpstan/Rule/EnforceExtendedClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public function reports_test_directly_extending_phpunits_test_case(): void
]);
}

#[Test]
public function does_not_report_abstract_test_directly_extending_phpunits_test_case(): void
{
$this->analyse([__DIR__.'/../data/AbstractTestCaseTest.php'], []);
}

#[Test]
public function reports_test_indirectly_extending_phpunits_test_case(): void
{
Expand Down
9 changes: 9 additions & 0 deletions tests/phpstan/data/AbstractTestCaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Tests\Phpstan\Lendable\PHPUnitExtensions\data;

use PHPUnit\Framework\TestCase;

abstract class AbstractTestCaseTest extends TestCase {}

0 comments on commit 994f17d

Please sign in to comment.