Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore abstract classes in strict mocking PHPStan rule #14

Merged
merged 3 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}