Skip to content
Closed
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
5 changes: 5 additions & 0 deletions config/sets/annotations-to-attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
use Rector\PHPUnit\ValueObject\AnnotationWithValueToAttribute;

return static function (RectorConfig $rectorConfig): void {
// safety check, not to run on PHPUnit 9 and bellow where are no attributes
if (! class_exists('PHPUnit\Framework\Attributes\DataProvider')) {
return;
}

$rectorConfig->rules([
TicketAnnotationToAttributeRector::class,
TestWithAnnotationToAttributeRector::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector\Fixture;

use PHPUnit\Framework\TestCase;

final class FooTest extends TestCase
{
/**
* @dataProvider \Tests\Foo\ExternalProvider::barProvider
**/
public function testBar()
{
self::assertTrue(true);
}
}

final class ExternalProvider
{
public static function barProvider()
{}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
Expand All @@ -35,6 +36,7 @@ public function __construct(
private readonly ReflectionResolver $reflectionResolver,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly ReflectionProvider $reflectionProvider,
) {
}

Expand Down Expand Up @@ -120,6 +122,11 @@ public function refactor(Node $node): ?Node
return null;
}

// safety check, no to upgrade phpunit annotations to soon
if (! $this->reflectionProvider->hasClass('PHPUnit\Framework\Attributes\DataProvider')) {
return null;
}

foreach ($desiredTagValueNodes as $desiredTagValueNode) {
if (! $desiredTagValueNode->value instanceof GenericTagValueNode) {
continue;
Expand Down
Loading