PHPUnit Data Provider Error - "no tests" or Wrong Argument Count
A @dataProvider / #[DataProvider] feeds argument sets into a test. In PHPUnit 10+ the provider must be static, return an iterable of argument arrays, and supply the exact number of parameters the test declares. Any mismatch errors the test or yields no cases.
What this error means
A data-provided test errors with "Data Provider method … is not static", "wrong number of arguments", or simply runs zero cases. The same provider worked on an older PHPUnit before the static requirement.
1) App\Tests\MathTest::testAdd
The data provider specified for App\Tests\MathTest::testAdd is invalid.
Data Provider method App\Tests\MathTest::additions() is not static.
# or
Too few arguments to function MathTest::testAdd(), 1 passed and exactly 2 expectedCommon causes
Provider is not static (PHPUnit 10+)
PHPUnit 10 requires data provider methods to be static. A non-static provider is rejected as invalid.
Return shape or argument count is wrong
A provider must return an iterable where each element is an array of arguments matching the test’s parameters. A flat array, missing element, or wrong count errors the test.
How to fix it
Make the provider static and well-shaped
Return an iterable of argument arrays; each inner array matches the test signature.
public static function additions(): array
{
return [
'two positives' => [2, 3, 5],
'with zero' => [0, 7, 7],
];
}
#[DataProvider('additions')]
public function testAdd(int $a, int $b, int $expected): void { /* ... */ }Align the argument count
- Count the values in each provider row and the test’s parameters.
- Ensure every row supplies exactly that many arguments.
- Use named keys for rows so failures report which case broke.
List the resolved cases
Confirm PHPUnit expands the provider into the cases you expect.
vendor/bin/phpunit --list-tests | grep testAddHow to prevent it
- Declare data providers
staticand type them withiterable/array. - Use named data sets so failures point at the right row.
- Run
--list-teststo verify providers expand into the expected cases.