Skip to content

Commit 9d2a0e6

Browse files
committed
Add impossible-check tests for eq and notEq
1 parent 9eda0cb commit 9d2a0e6

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

tests/Type/WebMozartAssert/ImpossibleCheckTypeMethodCallRuleTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,32 @@ public function testExtension(): void
4747
]);
4848
}
4949

50+
public function testEq(): void
51+
{
52+
$this->analyse([__DIR__ . '/data/impossible-check-eq-not-eq.php'], [
53+
[
54+
'Call to static method Webmozart\Assert\Assert::eq() with stdClass and stdClass will always evaluate to true.',
55+
11,
56+
],
57+
[
58+
'Call to static method Webmozart\Assert\Assert::notEq() with stdClass and stdClass will always evaluate to false.',
59+
12,
60+
],
61+
[
62+
'Call to static method Webmozart\Assert\Assert::eq() with stdClass and stdClass will always evaluate to true.',
63+
29,
64+
],
65+
[
66+
'Call to static method Webmozart\Assert\Assert::eq() with stdClass and null will always evaluate to false.',
67+
32,
68+
],
69+
[
70+
'Call to static method Webmozart\Assert\Assert::notEq() with stdClass and null will always evaluate to true.',
71+
33,
72+
],
73+
]);
74+
}
75+
5076
public function testBug8(): void
5177
{
5278
$this->analyse([__DIR__ . '/data/bug-8.php'], [
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace WebmozartAssertImpossibleCheckEqNotEq;
4+
5+
use DateTimeInterface;
6+
use stdClass;
7+
use Webmozart\Assert\Assert;
8+
9+
function sameInstancesAreAlwaysEqual(stdClass $a, stdClass $b): void
10+
{
11+
Assert::eq($a, $a); // will always evaluate to true
12+
Assert::notEq($b, $b); // will always evaluate to false
13+
}
14+
15+
function instancesOfTheSameTypeAreNotIdenticalButCouldBeEqual(stdClass $a, stdClass $b, stdClass $c, stdClass $d): void
16+
{
17+
Assert::eq($a, $b);
18+
Assert::notEq($c, $d);
19+
20+
Assert::eq(createStdClass(), createStdClass());
21+
Assert::notEq(createStdClass(), createStdClass());
22+
}
23+
24+
function instancesOfDifferentTypesAreNeverEqual(stdClass $a, DateTimeInterface $b, stdClass $c, DateTimeInterface $d, stdClass $e, stdClass $f, stdClass $g, stdClass $h): void
25+
{
26+
Assert::eq($a, $b); // ignored, should evaluate to false?
27+
Assert::notEq($c, $d); // ignored, should evaluate to true?
28+
29+
Assert::eq($e, new stdClass()); // will always evaluate to true, should evaluate to false?
30+
Assert::notEq($f, new stdClass()); // ignored, should evaluate to true?
31+
32+
Assert::eq($g, null); // will always evaluate to false
33+
Assert::notEq($h, null); // will always evaluate to true
34+
}
35+
36+
function createStdClass(): stdClass
37+
{
38+
return new stdClass();
39+
}

0 commit comments

Comments
 (0)