forked from phpstan/phpstan-phpunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttributeRequiresPhpVersionRuleTest.php
More file actions
95 lines (74 loc) · 2.15 KB
/
AttributeRequiresPhpVersionRuleTest.php
File metadata and controls
95 lines (74 loc) · 2.15 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
<?php declare(strict_types = 1);
namespace PHPStan\Rules\PHPUnit;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPStan\Type\FileTypeMapper;
/**
* @extends RuleTestCase<AttributeRequiresPhpVersionRule>
*/
final class AttributeRequiresPhpVersionRuleTest extends RuleTestCase
{
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,
],
]);
}
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,
);
}
}