|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Sabberworm\CSS\Tests\Unit\PhpStan; |
| 6 | + |
| 7 | +use PHPStan\Analyser\IgnoreErrorExtension; |
| 8 | +use PHPStan\Testing\RuleTestCase; |
| 9 | +use PHPStan\Rules\Comparison\ImpossibleCheckTypeFunctionCallRule; |
| 10 | +use PHPStan\Rules\Rule; |
| 11 | + |
| 12 | +/** |
| 13 | + * This covers `function.alreadyNarrowedType` error handling in the `IgnoreBooleanAlways` PHPStan extension class. |
| 14 | + * `RuleTestCase` allows only one `Rule` class, so separate `TestCase`s are needed for errors generated by other rules. |
| 15 | + * Note that the base class covers testing the suppression of the warning, and is included via `extends`. |
| 16 | + * This class covers the non-suppression of warnings in other contexts, which requires detailing the expected warnings. |
| 17 | + * |
| 18 | + * @covers \Sabberworm\CSS\PhpStan\IgnoreBooleanAlways |
| 19 | + */ |
| 20 | +final class IgnoreBooleanAlwaysImpossibleAssertTest extends IgnoreBooleanAlwaysTestBase |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @return ImpossibleCheckTypeFunctionCallRule |
| 24 | + */ |
| 25 | + protected function getRule(): Rule |
| 26 | + { |
| 27 | + // If the class is renamed or removed in the next major release of PHPStan, we'll deal with it then. |
| 28 | + // @phpstan-ignore phpstanApi.classConstant |
| 29 | + return self::getContainer()->getByType(ImpossibleCheckTypeFunctionCallRule::class); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @test |
| 34 | + */ |
| 35 | + public function warningIsRetainedForPointlessAssert(): void |
| 36 | + { |
| 37 | + // Skip the test in PHP/PHPStan configurations that don't have the required components. |
| 38 | + // It is good enough to test for those that do. |
| 39 | + if (!\interface_exists(IgnoreErrorExtension::class)) { |
| 40 | + self::markTestSkipped('This is testing the testers, and only needs to run whenever possible.'); |
| 41 | + } |
| 42 | + |
| 43 | + // Second argument is array of expected warnings. |
| 44 | + $this->analyse( |
| 45 | + [self::FIXTURES_DIR . 'alwaystrue-pointlessassert.php'], |
| 46 | + [ |
| 47 | + [ |
| 48 | + 'Call to function is_int() with int will always evaluate to true.', |
| 49 | + 7, |
| 50 | + ], |
| 51 | + ] |
| 52 | + ); |
| 53 | + } |
| 54 | +} |
0 commit comments