Skip to content

Commit 8b8fba1

Browse files
committed
more tests
1 parent 3f7b29d commit 8b8fba1

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/Rules/PHPUnit/AttributeRequiresPhpVersionRule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ public function processNode(Node $node, Scope $scope): array
8686
!is_numeric($args[0])
8787
) {
8888
try {
89+
// check composer like version constraints, e.g. ^1 or ~2
8990
$testPhpVersionConstraint = $parser->parse($args[0]);
9091

9192
if ($testPhpVersionConstraint->complies($this->phpstanPhpVersion)) {
9293
continue;
9394
}
9495
} catch (UnsupportedVersionConstraintException $e) {
96+
// test php-src builtin operators as in version_compare()
9597
if (preg_match(self::VERSION_COMPARISON, $args[0], $matches) <= 0) {
9698
$errors[] = RuleErrorBuilder::message(
9799
sprintf($e->getMessage()),

tests/Rules/PHPUnit/AttributeRequiresPhpVersionRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ public function testPhpVersionMismatch(): void
9292
'Version requirement will always evaluate to false.',
9393
12,
9494
],
95+
[
96+
'Version requirement will always evaluate to false.',
97+
20,
98+
],
99+
[
100+
'Version requirement will always evaluate to false.',
101+
28,
102+
],
103+
[
104+
'Version requirement will always evaluate to false.',
105+
36,
106+
],
95107
]);
96108
}
97109

tests/Rules/PHPUnit/data/requires-php-version-mismatch.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,58 @@ public function testFoo(): void {
1515
}
1616
}
1717

18+
class RequiresPhp5Caret extends TestCase
19+
{
20+
#[RequiresPhp('^5.0')]
21+
public function testFoo(): void {
22+
23+
}
24+
}
25+
26+
class RequiresPhp5Tilde extends TestCase
27+
{
28+
#[RequiresPhp('~5.0')]
29+
public function testFoo(): void {
30+
31+
}
32+
}
33+
34+
class RequiresPhp5Star extends TestCase
35+
{
36+
#[RequiresPhp('5.*')]
37+
public function testFoo(): void {
38+
39+
}
40+
}
41+
1842
class RequiresPhp8 extends TestCase
1943
{
2044
#[RequiresPhp('>=8.0')]
2145
public function testFoo(): void {
2246

2347
}
2448
}
49+
50+
class RequiresPhp8Caret extends TestCase
51+
{
52+
#[RequiresPhp('^8.0')]
53+
public function testFoo(): void {
54+
55+
}
56+
}
57+
58+
class RequiresPhp8Tilde extends TestCase
59+
{
60+
#[RequiresPhp('~8.0')]
61+
public function testFoo(): void {
62+
63+
}
64+
}
65+
66+
class RequiresPhp8Star extends TestCase
67+
{
68+
#[RequiresPhp('8.*')]
69+
public function testFoo(): void {
70+
71+
}
72+
}

0 commit comments

Comments
 (0)