Skip to content

Commit f91d89e

Browse files
committed
Error only when strict-rules are installed in tandem
1 parent 7d8c629 commit f91d89e

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"require": {
99
"php": "^7.4 || ^8.0",
10-
"phpstan/phpstan": "^2.0"
10+
"phpstan/phpstan": "^2.0.4"
1111
},
1212
"conflict": {
1313
"phpunit/phpunit": "<7.0"

rules.neon

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ rules:
22
- PHPStan\Rules\PHPUnit\AssertSameBooleanExpectedRule
33
- PHPStan\Rules\PHPUnit\AssertSameNullExpectedRule
44
- PHPStan\Rules\PHPUnit\AssertSameWithCountRule
5-
- PHPStan\Rules\PHPUnit\AssertEqualsIsDiscouragedRule
65
- PHPStan\Rules\PHPUnit\ClassCoversExistsRule
76
- PHPStan\Rules\PHPUnit\ClassMethodCoversExistsRule
87
- PHPStan\Rules\PHPUnit\MockMethodCallRule
@@ -18,3 +17,10 @@ services:
1817
deprecationRulesInstalled: %deprecationRulesInstalled%
1918
tags:
2019
- phpstan.rules.rule
20+
21+
-
22+
class: PHPStan\Rules\PHPUnit\AssertEqualsIsDiscouragedRule
23+
arguments:
24+
strictRulesInstalled: %strictRulesInstalled%
25+
tags:
26+
- phpstan.rules.rule

src/Rules/PHPUnit/AssertEqualsIsDiscouragedRule.php

+13
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,26 @@
1818
class AssertEqualsIsDiscouragedRule implements Rule
1919
{
2020

21+
private bool $strictRulesInstalled;
22+
23+
public function __construct(
24+
bool $strictRulesInstalled
25+
)
26+
{
27+
$this->strictRulesInstalled = $strictRulesInstalled;
28+
}
29+
2130
public function getNodeType(): string
2231
{
2332
return NodeAbstract::class;
2433
}
2534

2635
public function processNode(Node $node, Scope $scope): array
2736
{
37+
if (!$this->strictRulesInstalled) {
38+
return [];
39+
}
40+
2841
if (!AssertRuleHelper::isMethodOrStaticCallOnAssert($node, $scope)) {
2942
return [];
3043
}

tests/Rules/PHPUnit/AssertEqualsIsDiscouragedRuleTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testRule(): void
3232

3333
protected function getRule(): Rule
3434
{
35-
return new AssertEqualsIsDiscouragedRule();
35+
return new AssertEqualsIsDiscouragedRule(true);
3636
}
3737

3838
}

0 commit comments

Comments
 (0)