forked from phpstan/phpstan-phpunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassAttributeRequiresPhpVersionRuleTest.php
More file actions
75 lines (61 loc) · 1.71 KB
/
Copy pathClassAttributeRequiresPhpVersionRuleTest.php
File metadata and controls
75 lines (61 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php declare(strict_types = 1);
namespace PHPStan\Rules\PHPUnit;
use PHPStan\Php\ConfiguredPhpVersionRangeHelper;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
/**
* @extends RuleTestCase<ClassAttributeRequiresPhpVersionRule>
*/
final class ClassAttributeRequiresPhpVersionRuleTest extends RuleTestCase
{
private int $phpunitMajorVersion;
private int $phpunitMinorVersion;
private bool $warnAboutIncompleteVersion = false;
public function testWarnAboutIncompleteVersion(): void
{
$this->phpunitMajorVersion = 12;
$this->phpunitMinorVersion = 5;
$this->warnAboutIncompleteVersion = true;
$this->analyse([__DIR__ . '/data/requires-php-version-on-class.php'], [
[
'Version requirement will always evaluate to false.',
10,
],
[
'Version requirement is incomplete.',
10,
],
]);
}
public function testWarnAboutIncompletePhpunitVersion(): void
{
$this->phpunitMajorVersion = 12;
$this->phpunitMinorVersion = 5;
$this->warnAboutIncompleteVersion = true;
$this->analyse([__DIR__ . '/data/requires-phpunit-version.php'], [
[
'Version requirement is incomplete.',
18,
],
]);
}
protected function getRule(): Rule
{
$phpunitVersion = new PHPUnitVersion($this->phpunitMajorVersion, $this->phpunitMinorVersion);
return new ClassAttributeRequiresPhpVersionRule(
new AttributeVersionRequirementHelper(
$phpunitVersion,
self::getContainer()->getByType(ConfiguredPhpVersionRangeHelper::class), // @phpstan-ignore phpstanApi.classConstant
false,
true,
$this->warnAboutIncompleteVersion,
),
);
}
public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/ClassAttributeRequiresPhpVersionRule.neon',
];
}
}