Skip to content

Commit 07d2784

Browse files
committed
Use TypeSystem in AssertSameBooleanExpectedRule
1 parent 450bfc0 commit 07d2784

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Rules/PHPUnit/AssertSameBooleanExpectedRule.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,19 @@ public function processNode(Node $node, Scope $scope): array
4040
if (!($expectedArgumentValue instanceof ConstFetch)) {
4141
return [];
4242
}
43+
$expectedArgumentType = $scope->getType($expectedArgumentValue);
4344

4445
if (!AssertRuleHelper::isMethodOrStaticCallOnAssert($node, $scope)) {
4546
return [];
4647
}
4748

48-
if ($expectedArgumentValue->name->toLowerString() === 'true') {
49+
if ($expectedArgumentType->isTrue()->yes()) {
4950
return [
5051
RuleErrorBuilder::message('You should use assertTrue() instead of assertSame() when expecting "true"')->identifier('phpunit.assertTrue')->build(),
5152
];
5253
}
5354

54-
if ($expectedArgumentValue->name->toLowerString() === 'false') {
55+
if ($expectedArgumentType->isFalse()->yes()) {
5556
return [
5657
RuleErrorBuilder::message('You should use assertFalse() instead of assertSame() when expecting "false"')->identifier('phpunit.assertFalse')->build(),
5758
];

tests/Rules/PHPUnit/AssertSameBooleanExpectedRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public function testRule(): void
3131
'You should use assertTrue() instead of assertSame() when expecting "true"',
3232
26,
3333
],
34+
[
35+
'You should use assertTrue() instead of assertSame() when expecting "true"',
36+
31,
37+
],
38+
[
39+
'You should use assertFalse() instead of assertSame() when expecting "false"',
40+
32,
41+
],
3442
[
3543
'You should use assertTrue() instead of assertSame() when expecting "true"',
3644
74,

0 commit comments

Comments
 (0)