|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace mglaman\PHPStanDrupal\Tests\Rules; |
| 6 | + |
| 7 | +use mglaman\PHPStanDrupal\Rules\Drupal\Tests\TestClassSuffixNameRule; |
| 8 | +use mglaman\PHPStanDrupal\Tests\DrupalRuleTestCase; |
| 9 | +use PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper; |
| 10 | +use PHPStan\Rules\Comparison\ImpossibleCheckTypeStaticMethodCallRule; |
| 11 | +use PHPStan\Rules\Rule; |
| 12 | + |
| 13 | +class ImpossibleCheckTypeStaticMethodCallRuleTest extends DrupalRuleTestCase |
| 14 | +{ |
| 15 | + |
| 16 | + private bool $treatPhpDocTypesAsCertain = false; |
| 17 | + |
| 18 | + private bool $reportAlwaysTrueInLastCondition = false; |
| 19 | + |
| 20 | + protected function getRule(): Rule |
| 21 | + { |
| 22 | + /** @phpstan-ignore phpstanApi.constructor */ |
| 23 | + return new ImpossibleCheckTypeStaticMethodCallRule( |
| 24 | + /** @phpstan-ignore phpstanApi.constructor */ |
| 25 | + new ImpossibleCheckTypeHelper( |
| 26 | + $this->createReflectionProvider(), |
| 27 | + $this->getTypeSpecifier(), |
| 28 | + [], |
| 29 | + $this->treatPhpDocTypesAsCertain, |
| 30 | + false, |
| 31 | + ), |
| 32 | + true, |
| 33 | + $this->treatPhpDocTypesAsCertain, |
| 34 | + $this->reportAlwaysTrueInLastCondition, |
| 35 | + true, |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + protected function shouldTreatPhpDocTypesAsCertain(): bool |
| 40 | + { |
| 41 | + return $this->treatPhpDocTypesAsCertain; |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + public function testBug857(): void |
| 46 | + { |
| 47 | + $this->treatPhpDocTypesAsCertain = true; |
| 48 | + // It shouldn't report anything. |
| 49 | + $this->analyse([__DIR__ . '/data/bug-857.php'], []); |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments