Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Fixture;

use PHPUnit\Framework\TestCase;

/**
* @covers \Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\ExistingTrait
*/
final class CoversTrait extends TestCase
{
public function test()
{
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Fixture;

use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversTrait(\Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source\ExistingTrait::class)]
final class CoversTrait extends TestCase
{
public function test()
{
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);

namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector\Source;

trait ExistingTrait
{
public function __construct()
{
}

public function foo(): void
{
}

public function bar(): void
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ final class CoversAnnotationWithValueToAttributeRector extends AbstractRector im
*/
private const COVERTS_CLASS_ATTRIBUTE = 'PHPUnit\Framework\Attributes\CoversClass';

/**
* @var string
*/
private const COVERTS_TRAIT_ATTRIBUTE = 'PHPUnit\Framework\Attributes\CoversTrait';

/**
* @var string
*/
Expand Down Expand Up @@ -150,6 +155,15 @@ private function createAttributeGroup(string $annotationValue): AttributeGroup
$attributeValue = [$this->getClass($annotationValue) . '::class', $this->getMethod($annotationValue)];
} else {
$attributeClass = self::COVERTS_CLASS_ATTRIBUTE;

if ($this->reflectionProvider->hasClass($annotationValue)) {
$classReflection = $this->reflectionProvider->getClass($annotationValue);

if ($classReflection->isTrait()) {
$attributeClass = self::COVERTS_TRAIT_ATTRIBUTE;
}
}

$attributeValue = [trim($annotationValue) . '::class'];
}

Expand Down
Loading