-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathNoAssertFuncCallInTestsRule.php
More file actions
47 lines (39 loc) · 1.25 KB
/
NoAssertFuncCallInTestsRule.php
File metadata and controls
47 lines (39 loc) · 1.25 KB
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
<?php
namespace Symplify\PHPStanRules\Rules\PHPUnit;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use Symplify\PHPStanRules\Enum\RuleIdentifier\PHPUnitRuleIdentifier;
use Symplify\PHPStanRules\Helper\NamingHelper;
use Symplify\PHPStanRules\PHPUnit\TestClassDetector;
/**
* @implements Rule<FuncCall>
*/
final class NoAssertFuncCallInTestsRule implements Rule
{
public const string ERROR_MESSAGE = 'Instead of assert() that can miss important checks, use native PHPUnit assert call';
public function getNodeType(): string
{
return FuncCall::class;
}
/**
* @param FuncCall $node
* @return IdentifierRuleError[]
*/
public function processNode(Node $node, Scope $scope): array
{
if (! NamingHelper::isName($node->name, 'assert')) {
return [];
}
if (! TestClassDetector::isTestClass($scope)) {
return [];
}
$identifierRuleError = RuleErrorBuilder::message(self::ERROR_MESSAGE)
->identifier(PHPUnitRuleIdentifier::NO_ASSERT_FUNC_CALL_IN_TESTS)
->build();
return [$identifierRuleError];
}
}