|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Rules\PHPUnit; |
| 4 | + |
| 5 | +use PHPStan\Php\PhpVersion; |
| 6 | +use PHPStan\Rules\Rule; |
| 7 | +use PHPStan\Testing\RuleTestCase; |
| 8 | + |
| 9 | +/** |
| 10 | + * @extends RuleTestCase<ClassAttributeRequiresPhpVersionRule> |
| 11 | + */ |
| 12 | +final class ClassAttributeRequiresPhpVersionRuleTest extends RuleTestCase |
| 13 | +{ |
| 14 | + |
| 15 | + private int $phpVersion = 80500; |
| 16 | + |
| 17 | + private int $phpunitMajorVersion; |
| 18 | + |
| 19 | + private int $phpunitMinorVersion; |
| 20 | + |
| 21 | + private bool $warnAboutIncompleteVersion = false; |
| 22 | + |
| 23 | + public function testWarnAboutIncompleteVersion(): void |
| 24 | + { |
| 25 | + $this->phpunitMajorVersion = 12; |
| 26 | + $this->phpunitMinorVersion = 5; |
| 27 | + $this->warnAboutIncompleteVersion = true; |
| 28 | + |
| 29 | + $this->analyse([__DIR__ . '/data/requires-php-version-on-class.php'], [ |
| 30 | + [ |
| 31 | + 'Version requirement will always evaluate to false.', |
| 32 | + 10, |
| 33 | + ], |
| 34 | + [ |
| 35 | + 'Version requirement is incomplete.', |
| 36 | + 10, |
| 37 | + ], |
| 38 | + ]); |
| 39 | + } |
| 40 | + |
| 41 | + protected function getRule(): Rule |
| 42 | + { |
| 43 | + $phpunitVersion = new PHPUnitVersion($this->phpunitMajorVersion, $this->phpunitMinorVersion); |
| 44 | + |
| 45 | + return new ClassAttributeRequiresPhpVersionRule( |
| 46 | + new AttributeVersionRequirementHelper( |
| 47 | + $phpunitVersion, |
| 48 | + false, |
| 49 | + new PhpVersion($this->phpVersion), |
| 50 | + true, |
| 51 | + $this->warnAboutIncompleteVersion, |
| 52 | + ), |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + public static function getAdditionalConfigFiles(): array |
| 57 | + { |
| 58 | + return [ |
| 59 | + __DIR__ . '/ClassAttributeRequiresPhpVersionRule.neon', |
| 60 | + ]; |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments