|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Rules\PHPUnit; |
| 4 | + |
| 5 | +use PHPStan\Rules\Rule; |
| 6 | +use PHPStan\Testing\RuleTestCase; |
| 7 | +use PHPStan\Type\FileTypeMapper; |
| 8 | + |
| 9 | +/** |
| 10 | + * @extends RuleTestCase<AttributeRequiresPhpVersionRule> |
| 11 | + */ |
| 12 | +final class AttributeRequiresPhpVersionRuleTest extends RuleTestCase |
| 13 | +{ |
| 14 | + |
| 15 | + private ?int $phpunitMajorVersion; |
| 16 | + |
| 17 | + private ?int $phpunitMinorVersion; |
| 18 | + |
| 19 | + private bool $deprecationRulesInstalled = true; |
| 20 | + |
| 21 | + public function testRuleOnPHPUnitUnknown(): void |
| 22 | + { |
| 23 | + $this->phpunitMajorVersion = null; |
| 24 | + $this->phpunitMinorVersion = null; |
| 25 | + |
| 26 | + $this->analyse([__DIR__ . '/data/requires-php-version.php'], []); |
| 27 | + } |
| 28 | + |
| 29 | + public function testRuleOnPHPUnit115(): void |
| 30 | + { |
| 31 | + $this->phpunitMajorVersion = 11; |
| 32 | + $this->phpunitMinorVersion = 5; |
| 33 | + |
| 34 | + $this->analyse([__DIR__ . '/data/requires-php-version.php'], []); |
| 35 | + } |
| 36 | + |
| 37 | + public function testRuleOnPHPUnit123(): void |
| 38 | + { |
| 39 | + $this->phpunitMajorVersion = 12; |
| 40 | + $this->phpunitMinorVersion = 3; |
| 41 | + |
| 42 | + $this->analyse([__DIR__ . '/data/requires-php-version.php'], []); |
| 43 | + } |
| 44 | + |
| 45 | + public function testRuleOnPHPUnit124DeprecationsOn(): void |
| 46 | + { |
| 47 | + $this->phpunitMajorVersion = 12; |
| 48 | + $this->phpunitMinorVersion = 4; |
| 49 | + $this->deprecationRulesInstalled = true; |
| 50 | + |
| 51 | + $this->analyse([__DIR__ . '/data/requires-php-version.php'], [ |
| 52 | + [ |
| 53 | + 'Version requirement without operator is deprecated.', |
| 54 | + 12, |
| 55 | + ], |
| 56 | + ]); |
| 57 | + } |
| 58 | + |
| 59 | + public function testRuleOnPHPUnit124DeprecationsOff(): void |
| 60 | + { |
| 61 | + $this->phpunitMajorVersion = 12; |
| 62 | + $this->phpunitMinorVersion = 4; |
| 63 | + $this->deprecationRulesInstalled = false; |
| 64 | + |
| 65 | + $this->analyse([__DIR__ . '/data/requires-php-version.php'], []); |
| 66 | + } |
| 67 | + |
| 68 | + public function testRuleOnPHPUnit13(): void |
| 69 | + { |
| 70 | + $this->phpunitMajorVersion = 13; |
| 71 | + $this->phpunitMinorVersion = 0; |
| 72 | + |
| 73 | + $this->analyse([__DIR__ . '/data/requires-php-version.php'], [ |
| 74 | + [ |
| 75 | + 'Version requirement is missing operator.', |
| 76 | + 12, |
| 77 | + ], |
| 78 | + ]); |
| 79 | + } |
| 80 | + |
| 81 | + protected function getRule(): Rule |
| 82 | + { |
| 83 | + $phpunitVersion = new PHPUnitVersion($this->phpunitMajorVersion, $this->phpunitMinorVersion); |
| 84 | + |
| 85 | + return new AttributeRequiresPhpVersionRule( |
| 86 | + $phpunitVersion, |
| 87 | + new TestMethodsHelper( |
| 88 | + self::getContainer()->getByType(FileTypeMapper::class), |
| 89 | + $phpunitVersion, |
| 90 | + ), |
| 91 | + $this->deprecationRulesInstalled, |
| 92 | + ); |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments