Skip to content

Commit f7619c1

Browse files
committed
prefix PHP and PHPUnit version with >= in RequiresAnnotationWithValueToAttributeRector
1 parent 8f11285 commit f7619c1

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

rules-tests/AnnotationsToAttributes/Rector/Class_/RequiresAnnotationWithValueToAttributeRector/Fixture/requires_php.php.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\RequiresAnn
44

55
use PHPUnit\Framework\TestCase;
66

7+
/**
8+
* @requires PHP 8.0
9+
*/
710
class RequiresPHP extends TestCase
811
{
912
/**
@@ -22,6 +25,7 @@ namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\RequiresAnn
2225

2326
use PHPUnit\Framework\TestCase;
2427

28+
#[\PHPUnit\Framework\Attributes\RequiresPhp('>= 8.0')]
2529
class RequiresPHP extends TestCase
2630
{
2731
#[\PHPUnit\Framework\Attributes\RequiresPhp('> 8.4')]

rules-tests/AnnotationsToAttributes/Rector/Class_/RequiresAnnotationWithValueToAttributeRector/Fixture/requires_phpunit.php.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase;
66

77
/**
88
* @requires PHPUnit >= 10
9+
* @requires PHPUnit 5
910
*/
1011
final class RequiresPHPUnit extends TestCase
1112
{
@@ -20,6 +21,7 @@ namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\RequiresAnn
2021
use PHPUnit\Framework\TestCase;
2122

2223
#[\PHPUnit\Framework\Attributes\RequiresPhpunit('>= 10')]
24+
#[\PHPUnit\Framework\Attributes\RequiresPhpunit('>= 5')]
2325
final class RequiresPHPUnit extends TestCase
2426
{
2527
}

rules/AnnotationsToAttributes/NodeFactory/RequiresAttributeFactory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@ public function create(string $annotationValue): ?AttributeGroup
2424
switch ($type) {
2525
case 'PHP':
2626
$attributeClass = 'PHPUnit\Framework\Attributes\RequiresPhp';
27+
28+
// only version is used, we need to prefix with >=
29+
if (is_string($attributeValue) && is_numeric($attributeValue[0])) {
30+
$attributeValue = '>= ' . $attributeValue;
31+
}
32+
2733
$attributeValue = [$attributeValue];
2834
break;
2935
case 'PHPUnit':
3036
$attributeClass = 'PHPUnit\Framework\Attributes\RequiresPhpunit';
37+
38+
// only version is used, we need to prefix with >=
39+
if (is_string($attributeValue) && is_numeric($attributeValue[0])) {
40+
$attributeValue = '>= ' . $attributeValue;
41+
}
42+
3143
$attributeValue = [$attributeValue];
3244
break;
3345
case 'OS':

0 commit comments

Comments
 (0)