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,48 @@
<?php

declare(strict_types=1);

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class BothAnnotationAndAttributeExists extends TestCase
{
/** @dataProvider provideData */
#[DataProvider('provideData')]
public function testExample(string $value): void
{
self::assertNotEmpty($value);
}

public static function provideData(): iterable
{
yield 'case 1' => ['foo'];
yield 'case 2' => ['bar'];
}
}

?>
-----
<?php

declare(strict_types=1);

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class BothAnnotationAndAttributeExists extends TestCase
{
#[DataProvider('provideData')]
public function testExample(string $value): void
{
self::assertNotEmpty($value);
}

public static function provideData(): iterable
{
yield 'case 1' => ['foo'];
yield 'case 2' => ['bar'];
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ public function refactor(Node $node): ?Node
continue;
}

$node->attrGroups[] = $this->createAttributeGroup($originalAttributeValueToken);
$attributeGroup = $this->createAttributeGroup($node, $originalAttributeValueToken);

if ($attributeGroup instanceof AttributeGroup) {
$node->attrGroups[] = $attributeGroup;
}

// cleanup
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode);
Expand All @@ -159,7 +163,7 @@ public function refactor(Node $node): ?Node
return $node;
}

private function createAttributeGroup(string $originalAttributeValue): AttributeGroup
private function createAttributeGroup(ClassMethod $classMethod, string $originalAttributeValue): ?AttributeGroup
{
$methodName = trim($originalAttributeValue, '()');

Expand All @@ -173,12 +177,23 @@ private function createAttributeGroup(string $originalAttributeValue): Attribute
$className = '\\' . $className;
}

return $this->phpAttributeGroupFactory->createFromClassWithItems(
$attributeGroup = $this->phpAttributeGroupFactory->createFromClassWithItems(
'PHPUnit\Framework\Attributes\DataProviderExternal',
[$className . '::class', $methodName]
);
} else {
$attributeGroup = $this->phpAttributeGroupFactory->createFromClassWithItems(
self::DATA_PROVIDER_CLASS,
[$methodName]
);
}

foreach ($classMethod->attrGroups as $existingAttributeGroup) {
if ($this->nodeComparator->areNodesEqual($existingAttributeGroup, $attributeGroup)) {
return null;
}
}

return $this->phpAttributeGroupFactory->createFromClassWithItems(self::DATA_PROVIDER_CLASS, [$methodName]);
return $attributeGroup;
}
}