Skip to content

Commit 8fd9fca

Browse files
committed
More tests
1 parent 9dd5b64 commit 8fd9fca

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,15 @@ public function dataReportAlwaysTrueInLastCondition(): iterable
358358
'Match arm is unreachable because previous comparison is always true.',
359359
24,
360360
],
361+
[
362+
'Match arm comparison between $this(MatchAlwaysTrueLastArm\Foo)&MatchAlwaysTrueLastArm\Foo::BAR and MatchAlwaysTrueLastArm\Foo::BAR is always true.',
363+
49,
364+
'Remove remaining cases below this one and this error will disappear too.',
365+
],
366+
[
367+
'Match arm is unreachable because previous comparison is always true.',
368+
50,
369+
],
361370
]];
362371
yield [true, false, [
363372
[
@@ -372,13 +381,30 @@ public function dataReportAlwaysTrueInLastCondition(): iterable
372381
'Match arm is unreachable because previous comparison is always true.',
373382
24,
374383
],
384+
[
385+
'Match arm comparison between $this(MatchAlwaysTrueLastArm\Foo)&MatchAlwaysTrueLastArm\Foo::BAR and MatchAlwaysTrueLastArm\Foo::BAR is always true.',
386+
45,
387+
],
388+
[
389+
'Match arm comparison between $this(MatchAlwaysTrueLastArm\Foo)&MatchAlwaysTrueLastArm\Foo::BAR and MatchAlwaysTrueLastArm\Foo::BAR is always true.',
390+
49,
391+
],
392+
[
393+
'Match arm is unreachable because previous comparison is always true.',
394+
50,
395+
],
375396
]];
376397
yield [false, true, [
377398
[
378399
'Match arm comparison between $this(MatchAlwaysTrueLastArm\Foo)&MatchAlwaysTrueLastArm\Foo::BAR and MatchAlwaysTrueLastArm\Foo::BAR is always true.',
379400
23,
380401
'Remove remaining cases below this one and this error will disappear too.',
381402
],
403+
[
404+
'Match arm comparison between $this(MatchAlwaysTrueLastArm\Foo)&MatchAlwaysTrueLastArm\Foo::BAR and MatchAlwaysTrueLastArm\Foo::BAR is always true.',
405+
49,
406+
'Remove remaining cases below this one and this error will disappear too.',
407+
],
382408
]];
383409
yield [true, true, [
384410
[
@@ -389,6 +415,14 @@ public function dataReportAlwaysTrueInLastCondition(): iterable
389415
'Match arm comparison between $this(MatchAlwaysTrueLastArm\Foo)&MatchAlwaysTrueLastArm\Foo::BAR and MatchAlwaysTrueLastArm\Foo::BAR is always true.',
390416
23,
391417
],
418+
[
419+
'Match arm comparison between $this(MatchAlwaysTrueLastArm\Foo)&MatchAlwaysTrueLastArm\Foo::BAR and MatchAlwaysTrueLastArm\Foo::BAR is always true.',
420+
45,
421+
],
422+
[
423+
'Match arm comparison between $this(MatchAlwaysTrueLastArm\Foo)&MatchAlwaysTrueLastArm\Foo::BAR and MatchAlwaysTrueLastArm\Foo::BAR is always true.',
424+
49,
425+
],
392426
]];
393427
}
394428

tests/PHPStan/Rules/Comparison/data/match-always-true-last-arm.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,16 @@ public function doBaz(): void
3939
};
4040
}
4141

42+
public function doMoreConditionsInLastArm(): void
43+
{
44+
match ($this) {
45+
self::FOO, self::BAR => 1,
46+
};
47+
48+
match ($this) {
49+
self::FOO, self::BAR => 1,
50+
default => 2,
51+
};
52+
}
53+
4254
}

0 commit comments

Comments
 (0)