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
10 changes: 9 additions & 1 deletion src/Rules/PHPUnit/DataProviderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use function array_merge;
use function count;
use function explode;
use function is_string;
use function preg_match;
use function sprintf;

Expand Down Expand Up @@ -287,9 +288,16 @@ private function yieldDataProviderAttributes($node, ClassReflection $classReflec
continue;
}

// phpunit does not support named arguments.
// we handle them here just to make sure we don't crash on them.
$methodName = $args[0] ?? $args['methodName'] ?? null;
if (!is_string($methodName)) {
continue;
}

$startLine = $node->getStartLine();

yield [$classReflection, $args[0], $startLine];
yield [$classReflection, $methodName, $startLine];
}

return;
Expand Down
4 changes: 4 additions & 0 deletions tests/Rules/PHPUnit/EmptyDataProviderRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public function testRule(?int $version): void
'Data provider method provideData() provides no data sets, which is an error in PHPUnit 10 and newer.',
173,
];
$errors[] = [
'Data provider method provideData() provides no data sets, which is an error in PHPUnit 10 and newer.',
336,
];
}

$this->analyse([__DIR__ . '/data/empty-data-provider.php'], $errors);
Expand Down
17 changes: 17 additions & 0 deletions tests/Rules/PHPUnit/data/empty-data-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,20 @@ public function dataFileAsserts(): iterable
*/
public function testFileAsserts() {}
}

class NamedArgumentAttributeTest extends TestCase
{

// phpunit does not support named arguments.
// we handle them here just to make sure we don't crash on them.
#[DataProvider(methodName: 'provideData')]
public function testFoo(string $input): void
{
}

public static function provideData(): iterable
{
return [];
}

}