Skip to content

Commit 3cb2670

Browse files
committed
More impossible-check eq and notEq tests, target next PHPStan version
1 parent b3bbd12 commit 3cb2670

File tree

3 files changed

+88
-11
lines changed

3 files changed

+88
-11
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"require": {
99
"php": "^7.1 || ^8.0",
10-
"phpstan/phpstan": "^1.4.8"
10+
"phpstan/phpstan": "^1.4.9"
1111
},
1212
"require-dev": {
1313
"nikic/php-parser": "^4.13.0",

tests/Type/WebMozartAssert/ImpossibleCheckTypeMethodCallRuleTest.php

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,68 @@ public function testEqNotEq(): void
5959
12,
6060
],
6161
[
62-
'Call to static method Webmozart\Assert\Assert::eq() with stdClass and stdClass will always evaluate to true.',
63-
30,
62+
'Call to static method Webmozart\Assert\Assert::eq() with 1 and \'1\' will always evaluate to true.',
63+
34,
64+
],
65+
[
66+
'Call to static method Webmozart\Assert\Assert::notEq() with 1 and \'1\' will always evaluate to false.',
67+
35,
68+
],
69+
[
70+
'Call to static method Webmozart\Assert\Assert::eq() with 1 and true will always evaluate to true.',
71+
36,
72+
],
73+
[
74+
'Call to static method Webmozart\Assert\Assert::notEq() with 1 and true will always evaluate to false.',
75+
37,
76+
],
77+
[
78+
'Call to static method Webmozart\Assert\Assert::eq() with \'php\' and true will always evaluate to true.',
79+
38,
80+
],
81+
[
82+
'Call to static method Webmozart\Assert\Assert::notEq() with \'php\' and true will always evaluate to false.',
83+
39,
84+
],
85+
[
86+
'Call to static method Webmozart\Assert\Assert::eq() with \'\' and false will always evaluate to true.',
87+
40,
88+
],
89+
[
90+
'Call to static method Webmozart\Assert\Assert::notEq() with \'\' and false will always evaluate to false.',
91+
41,
92+
],
93+
[
94+
'Call to static method Webmozart\Assert\Assert::eq() with 1 and 1 will always evaluate to true.',
95+
43,
96+
],
97+
[
98+
'Call to static method Webmozart\Assert\Assert::notEq() with 1 and 1 will always evaluate to false.',
99+
44,
100+
],
101+
[
102+
'Call to static method Webmozart\Assert\Assert::eq() with true and true will always evaluate to true.',
103+
45,
104+
],
105+
[
106+
'Call to static method Webmozart\Assert\Assert::notEq() with true and true will always evaluate to false.',
107+
46,
108+
],
109+
[
110+
'Call to static method Webmozart\Assert\Assert::eq() with \'php\' and \'php\' will always evaluate to true.',
111+
47,
112+
],
113+
[
114+
'Call to static method Webmozart\Assert\Assert::notEq() with \'php\' and \'php\' will always evaluate to false.',
115+
48,
64116
],
65117
[
66118
'Call to static method Webmozart\Assert\Assert::eq() with stdClass and null will always evaluate to false.',
67-
33,
119+
58,
68120
],
69121
[
70122
'Call to static method Webmozart\Assert\Assert::notEq() with stdClass and null will always evaluate to true.',
71-
34,
123+
59,
72124
],
73125
]);
74126
}

tests/Type/WebMozartAssert/data/impossible-check-eq-not-eq.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,42 @@ function instancesOfTheSameTypeAreNotIdenticalButCouldBeEqual(stdClass $a, stdCl
2121
Assert::notEq(createStdClass(), createStdClass());
2222
}
2323

24-
function instancesOfDifferentTypesAreNeverEqual(stdClass $a, DateTimeInterface $b, stdClass $c, DateTimeInterface $d, stdClass $e, stdClass $f, stdClass $g, stdClass $h): void
24+
function looseVariableComparisonsAreNotSupported(stdClass $a, DateTimeInterface $b, stdClass $c, DateTimeInterface $d, string $e, int $f, string $g, int $h): void
2525
{
26-
// These don't report anything as PHPStan doesn't currently support loose comparison with ==
2726
Assert::eq($a, $b);
2827
Assert::notEq($c, $d);
28+
Assert::eq($e, $f);
29+
Assert::notEq($g, $h);
30+
}
31+
32+
function constantComparisons(): void
33+
{
34+
Assert::eq(1, '1'); // will always evaluate to true
35+
Assert::notEq(1, '1'); // will always evaluate to false
36+
Assert::eq(1, true); // will always evaluate to true
37+
Assert::notEq(1, true); // will always evaluate to false
38+
Assert::eq('php', true); // will always evaluate to true
39+
Assert::notEq('php', true); // will always evaluate to false
40+
Assert::eq('', false); // will always evaluate to true
41+
Assert::notEq('', false); // will always evaluate to false
2942

30-
Assert::eq($e, new stdClass()); // will always evaluate to true, should not report anything
31-
Assert::notEq($f, new stdClass());
43+
Assert::eq(1, 1); // will always evaluate to true
44+
Assert::notEq(1, 1); // will always evaluate to false
45+
Assert::eq(true, true); // will always evaluate to true
46+
Assert::notEq(true, true); // will always evaluate to false
47+
Assert::eq('php', 'php'); // will always evaluate to true
48+
Assert::notEq('php', 'php'); // will always evaluate to false
49+
}
50+
51+
function instancesOfDifferentTypesAreNeverEqual(stdClass $a, stdClass $b, stdClass $c, stdClass $d, stdClass $e, stdClass $f): void
52+
{
53+
Assert::eq($a, new stdClass());
54+
Assert::eq($b, createStdClass());
55+
Assert::notEq($c, new stdClass());
56+
Assert::notEq($d, createStdClass());
3257

33-
Assert::eq($g, null); // will always evaluate to false
34-
Assert::notEq($h, null); // will always evaluate to true
58+
Assert::eq($e, null); // will always evaluate to false
59+
Assert::notEq($f, null); // will always evaluate to true
3560
}
3661

3762
function createStdClass(): stdClass

0 commit comments

Comments
 (0)