-
Notifications
You must be signed in to change notification settings - Fork 3
/
DisallowPHPUnitRule.php
49 lines (41 loc) · 1.08 KB
/
DisallowPHPUnitRule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Worksome\CodingStyle\PHPStan;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPUnit\Framework\TestCase;
/**
* @implements Rule<Class_>
*/
final class DisallowPHPUnitRule implements Rule
{
public function getNodeType(): string
{
return Class_::class;
}
/**
* @param Class_ $node
*/
public function processNode(Node $node, Scope $scope): array
{
if ($node->isAbstract()) {
return [];
}
if ($node->namespacedName === null) {
return [];
}
if (! is_subclass_of($node->namespacedName->toString(), TestCase::class)) {
return [];
}
return [
RuleErrorBuilder::message(
'PHPUnit tests are not allowed. Please use Pest PHP instead. If this is a TestCase, make it abstract to pass validation.'
)
->identifier('worksome.disallowPhpunit')
->build(),
];
}
}