44
55use PHPStan \Rules \Rule ;
66use PHPStan \Testing \RuleTestCase ;
7- use PHPUnit \Framework \Attributes \DataProvider ;
87use PHPUnit \Framework \Attributes \RequiresPhp ;
98
109/**
@@ -15,8 +14,6 @@ class MatchExpressionRuleTest extends RuleTestCase
1514
1615 private bool $ treatPhpDocTypesAsCertain = true ;
1716
18- private bool $ reportAlwaysTrueInLastCondition = false ;
19-
2017 protected function getRule (): Rule
2118 {
2219 return new MatchExpressionRule (
@@ -29,7 +26,6 @@ protected function getRule(): Rule
2926 ),
3027 $ this ->treatPhpDocTypesAsCertain ,
3128 ),
32- $ this ->reportAlwaysTrueInLastCondition ,
3329 $ this ->treatPhpDocTypesAsCertain ,
3430 );
3531 }
@@ -280,21 +276,11 @@ public function testLastArmAlwaysTrue(): void
280276 ]);
281277 }
282278
283- public static function dataReportAlwaysTrueInLastCondition (): iterable
279+ #[RequiresPhp('>= 8.1 ' )]
280+ public function testLastCondition (): void
284281 {
285- yield [false , [
286- [
287- 'Match arm comparison between $this(MatchAlwaysTrueLastArm\Foo)&MatchAlwaysTrueLastArm\Foo::BAR and MatchAlwaysTrueLastArm\Foo::BAR is always true. ' ,
288- 23 ,
289- 'Remove remaining cases below this one and this error will disappear too. ' ,
290- ],
291- [
292- 'Match arm comparison between $this(MatchAlwaysTrueLastArm\Foo)&MatchAlwaysTrueLastArm\Foo::BAR and MatchAlwaysTrueLastArm\Foo::BAR is always true. ' ,
293- 49 ,
294- 'Remove remaining cases below this one and this error will disappear too. ' ,
295- ],
296- ]];
297- yield [true , [
282+ $ this ->treatPhpDocTypesAsCertain = true ;
283+ $ this ->analyse ([__DIR__ . '/data/match-always-true-last-arm.php ' ], [
298284 [
299285 'Match arm comparison between $this(MatchAlwaysTrueLastArm\Foo)&MatchAlwaysTrueLastArm\Foo::BAR and MatchAlwaysTrueLastArm\Foo::BAR is always true. ' ,
300286 23 ,
@@ -305,23 +291,7 @@ public static function dataReportAlwaysTrueInLastCondition(): iterable
305291 49 ,
306292 'Remove remaining cases below this one and this error will disappear too. ' ,
307293 ],
308- [
309- 'Match arm comparison between false and false is always true. ' ,
310- 58 ,
311- ],
312- ]];
313- }
314-
315- /**
316- * @param list<array{0: string, 1: int, 2?: string}> $expectedErrors
317- */
318- #[RequiresPhp('>= 8.1 ' )]
319- #[DataProvider('dataReportAlwaysTrueInLastCondition ' )]
320- public function testReportAlwaysTrueInLastCondition (bool $ reportAlwaysTrueInLastCondition , array $ expectedErrors ): void
321- {
322- $ this ->treatPhpDocTypesAsCertain = true ;
323- $ this ->reportAlwaysTrueInLastCondition = $ reportAlwaysTrueInLastCondition ;
324- $ this ->analyse ([__DIR__ . '/data/match-always-true-last-arm.php ' ], $ expectedErrors );
294+ ]);
325295 }
326296
327297 #[RequiresPhp('>= 8.0 ' )]
0 commit comments