Skip to content

Commit 6e74eb8

Browse files
committed
[AnnotationsToAttributes] Fix @Covers qualified::method conversion
1 parent 0ba734c commit 6e74eb8

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

rules-tests/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector/Fixture/covers_class.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
* @covers \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\ExistingClass
9+
* @covers \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\AnotherExistingClass::someMethod
910
*/
1011
final class CoversClass extends TestCase
1112
{
@@ -23,6 +24,7 @@ namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnot
2324
use PHPUnit\Framework\TestCase;
2425

2526
#[\PHPUnit\Framework\Attributes\CoversClass(\Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\ExistingClass::class)]
27+
#[\PHPUnit\Framework\Attributes\CoversClass(\Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\AnotherExistingClass::class)]
2628
final class CoversClass extends TestCase
2729
{
2830
public function test()

rules-tests/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector/Fixture/covers_method.php.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ final class CoversMethod extends TestCase
1212
public function test()
1313
{
1414
}
15+
16+
/**
17+
* @covers \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\AnotherExistingClass::someMethod
18+
*/
19+
public function test_foo()
20+
{
21+
}
1522
}
1623

1724
?>
@@ -23,11 +30,16 @@ namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnot
2330
use PHPUnit\Framework\TestCase;
2431

2532
#[\PHPUnit\Framework\Attributes\CoversClass(\Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\ExistingClass::class)]
33+
#[\PHPUnit\Framework\Attributes\CoversClass(\Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\AnotherExistingClass::class)]
2634
final class CoversMethod extends TestCase
2735
{
2836
public function test()
2937
{
3038
}
39+
40+
public function test_foo()
41+
{
42+
}
3143
}
3244

3345
?>

rules/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ private function createAttributeGroup(string $annotationValue): AttributeGroup
140140
if (str_starts_with($annotationValue, '::')) {
141141
$attributeClass = self::COVERS_FUNCTION_ATTRIBUTE;
142142
$attributeValue = trim($annotationValue, ':()');
143+
} elseif (str_contains($annotationValue, '::')) {
144+
$attributeClass = self::COVERTS_CLASS_ATTRIBUTE;
145+
$attributeValue = $this->getClass($annotationValue) . '::class';
143146
} else {
144147
$attributeClass = self::COVERTS_CLASS_ATTRIBUTE;
145148
$attributeValue = trim($annotationValue) . '::class';

0 commit comments

Comments
 (0)