File tree Expand file tree Collapse file tree 3 files changed +66
-0
lines changed
rules-tests/AnnotationsToAttributes/Rector/Class_/CoversAnnotationWithValueToAttributeRector
rules/AnnotationsToAttributes/Rector/Class_ Expand file tree Collapse file tree 3 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \AnnotationsToAttributes \Rector \Class_ \CoversAnnotationWithValueToAttributeRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+
7+ /**
8+ * @covers \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\ExistingTrait
9+ */
10+ final class CoversTrait extends TestCase
11+ {
12+ public function test ()
13+ {
14+ }
15+ }
16+
17+ ?>
18+ -----
19+ <?php
20+
21+ namespace Rector \PHPUnit \Tests \AnnotationsToAttributes \Rector \Class_ \CoversAnnotationWithValueToAttributeRector \Fixture ;
22+
23+ use PHPUnit \Framework \TestCase ;
24+
25+ #[\PHPUnit \Framework \Attributes \CoversTrait(\Rector \PHPUnit \Tests \AnnotationsToAttributes \Rector \Class_ \CoversAnnotationWithValueToAttributeRector \Source \ExistingTrait::class)]
26+ final class CoversTrait extends TestCase
27+ {
28+ public function test ()
29+ {
30+ }
31+ }
32+
33+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Rector \PHPUnit \Tests \AnnotationsToAttributes \Rector \Class_ \CoversAnnotationWithValueToAttributeRector \Source ;
5+
6+ trait ExistingTrait
7+ {
8+ public function __construct ()
9+ {
10+ }
11+
12+ public function foo (): void
13+ {
14+ }
15+
16+ public function bar (): void
17+ {
18+ }
19+ }
Original file line number Diff line number Diff line change @@ -38,6 +38,11 @@ final class CoversAnnotationWithValueToAttributeRector extends AbstractRector im
3838 */
3939 private const COVERTS_CLASS_ATTRIBUTE = 'PHPUnit\Framework\Attributes\CoversClass ' ;
4040
41+ /**
42+ * @var string
43+ */
44+ private const COVERTS_TRAIT_ATTRIBUTE = 'PHPUnit\Framework\Attributes\CoversTrait ' ;
45+
4146 /**
4247 * @var string
4348 */
@@ -150,6 +155,15 @@ private function createAttributeGroup(string $annotationValue): AttributeGroup
150155 $ attributeValue = [$ this ->getClass ($ annotationValue ) . '::class ' , $ this ->getMethod ($ annotationValue )];
151156 } else {
152157 $ attributeClass = self ::COVERTS_CLASS_ATTRIBUTE ;
158+
159+ if ($ this ->reflectionProvider ->hasClass ($ annotationValue )) {
160+ $ classReflection = $ this ->reflectionProvider ->getClass ($ annotationValue );
161+
162+ if ($ classReflection ->isTrait ()) {
163+ $ attributeClass = self ::COVERTS_TRAIT_ATTRIBUTE ;
164+ }
165+ }
166+
153167 $ attributeValue = [trim ($ annotationValue ) . '::class ' ];
154168 }
155169
You can’t perform that action at this time.
0 commit comments