-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathAttributeRequiresPhpVersionRuleTest.php
More file actions
139 lines (113 loc) · 3.1 KB
/
AttributeRequiresPhpVersionRuleTest.php
File metadata and controls
139 lines (113 loc) · 3.1 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php declare(strict_types = 1);
namespace PHPStan\Rules\PHPUnit;
use PHPStan\Php\PhpVersion;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPStan\Type\FileTypeMapper;
/**
* @extends RuleTestCase<AttributeRequiresPhpVersionRule>
*/
final class AttributeRequiresPhpVersionRuleTest extends RuleTestCase
{
private int $phpVersion = 80500;
private ?int $phpunitMajorVersion;
private ?int $phpunitMinorVersion;
private bool $deprecationRulesInstalled = true;
public function testRuleOnPHPUnitUnknown(): void
{
$this->phpunitMajorVersion = null;
$this->phpunitMinorVersion = null;
$this->analyse([__DIR__ . '/data/requires-php-version.php'], []);
}
public function testRuleOnPHPUnit115(): void
{
$this->phpunitMajorVersion = 11;
$this->phpunitMinorVersion = 5;
$this->analyse([__DIR__ . '/data/requires-php-version.php'], []);
}
public function testRuleOnPHPUnit123(): void
{
$this->phpunitMajorVersion = 12;
$this->phpunitMinorVersion = 3;
$this->analyse([__DIR__ . '/data/requires-php-version.php'], []);
}
public function testRuleOnPHPUnit124DeprecationsOn(): void
{
$this->phpunitMajorVersion = 12;
$this->phpunitMinorVersion = 4;
$this->deprecationRulesInstalled = true;
$this->analyse([__DIR__ . '/data/requires-php-version.php'], [
[
'Version requirement without operator is deprecated.',
12,
],
]);
}
public function testRuleOnPHPUnit124DeprecationsOff(): void
{
$this->phpunitMajorVersion = 12;
$this->phpunitMinorVersion = 4;
$this->deprecationRulesInstalled = false;
$this->analyse([__DIR__ . '/data/requires-php-version.php'], []);
}
public function testRuleOnPHPUnit13(): void
{
$this->phpunitMajorVersion = 13;
$this->phpunitMinorVersion = 0;
$this->analyse([__DIR__ . '/data/requires-php-version.php'], [
[
'Version requirement is missing operator.',
12,
],
]);
}
public function testPhpVersionMismatch(): void
{
$this->phpunitMajorVersion = 12;
$this->phpunitMinorVersion = 4;
$this->deprecationRulesInstalled = false;
$this->analyse([__DIR__ . '/data/requires-php-version-mismatch.php'], [
[
'Version requirement will always evaluate to false.',
12,
],
[
'Version requirement will always evaluate to false.',
20,
],
[
'Version requirement will always evaluate to false.',
28,
],
[
'Version requirement will always evaluate to false.',
36,
],
]);
}
public function testInvalidPhpVersion(): void
{
$this->phpunitMajorVersion = 12;
$this->phpunitMinorVersion = 4;
$this->deprecationRulesInstalled = false;
$this->analyse([__DIR__ . '/data/requires-php-version-invalid.php'], [
[
'Version constraint abc is not supported.',
12,
],
]);
}
protected function getRule(): Rule
{
$phpunitVersion = new PHPUnitVersion($this->phpunitMajorVersion, $this->phpunitMinorVersion);
return new AttributeRequiresPhpVersionRule(
$phpunitVersion,
new TestMethodsHelper(
self::getContainer()->getByType(FileTypeMapper::class),
$phpunitVersion,
),
$this->deprecationRulesInstalled,
new PhpVersion($this->phpVersion),
);
}
}