sebastianbergmann/phpunit · error · InvalidDataProviderException
Data Provider method %s::%s() expects an argument
Error message
Data Provider method %s::%s() expects an argument
What it means
Thrown while resolving a data provider when the method declares at least one parameter (ReflectionMethod::getNumberOfParameters() > 0). PHPUnit invokes providers with zero arguments, so a provider that expects parameters cannot be called and is rejected.
Source
Thrown at src/Metadata/Api/DataProvider.php:149
'Data Provider method %s::%s() is not public',
$className,
$methodName,
),
);
}
if (!$method->isStatic()) {
throw new InvalidDataProviderException(
sprintf(
'Data Provider method %s::%s() is not static',
$className,
$methodName,
),
);
}
if ($method->getNumberOfParameters() > 0) {
throw new InvalidDataProviderException(
sprintf(
'Data Provider method %s::%s() expects an argument',
$className,
$methodName,
),
);
}
/** @phpstan-ignore staticMethod.dynamicName */
$data = $className::$methodName();
if (!is_iterable($data)) {
throw new InvalidDataProviderException(
sprintf(
'Data Provider method %s::%s() does not return an iterable',
$className,
$methodName,
),View on GitHub (pinned to f123cdb2a2)
Solutions
- Remove the parameters from the provider method and resolve any needed values inside its body
- If configuration is needed, read it from constants/env/fixures within the provider instead of parameters
Example fix
// before
public static function provideCases(int $count): array
{
return array_fill(0, $count, [1]);
}
// after
public static function provideCases(): array
{
$count = 3;
return array_fill(0, $count, [1]);
} Defensive patterns
Strategy: validation
Validate before calling
$method = new ReflectionMethod($testClass, 'provideCases');
if ($method->getNumberOfParameters() > 0) {
// refactor to a zero-parameter provider before running
} Type guard
function isValidDataProvider(ReflectionMethod $method): bool
{
return $method->isPublic()
&& $method->isStatic()
&& $method->getNumberOfParameters() === 0;
} Prevention
- Keep providers parameterless; resolve configuration inside the method body
- Review provider signatures when refactoring helpers into providers
When it happens
Trigger: A provider method with a signature like 'public static function provideCases(string $context): array' referenced through @dataProvider.
Common situations: Providers that were originally helper methods taking arguments; refactorings that injected configuration parameters into a previously parameterless provider.
Related errors
- Data Provider method %s::%s() is not public
- Data Provider method %s::%s() is not static
- Comparison method %s::%s() does not exist.
- Comparison method %s::%s() does not declare exactly one para
- Return value for %s::%s() cannot be generated: %s
AI-assisted analysis of sebastianbergmann/phpunit@f123cdb2a2 (2026-08-23).
Data as JSON: /api/errors/1ffaa792367b44b2.
Report an issue: GitHub.