{"record":{"id":"1ffaa792367b44b2","repo":"sebastianbergmann/phpunit","slug":"data-provider-method-s-s-expects-an-argument","errorCode":null,"errorMessage":"Data Provider method %s::%s() expects an argument","messagePattern":"Data Provider method (.+?)::(.+?)\\(\\) expects an argument","errorType":"exception","errorClass":"InvalidDataProviderException","httpStatus":null,"severity":"error","filePath":"src/Metadata/Api/DataProvider.php","lineNumber":149,"sourceCode":"                            'Data Provider method %s::%s() is not public',\n                            $className,\n                            $methodName,\n                        ),\n                    );\n                }\n\n                if (!$method->isStatic()) {\n                    throw new InvalidDataProviderException(\n                        sprintf(\n                            'Data Provider method %s::%s() is not static',\n                            $className,\n                            $methodName,\n                        ),\n                    );\n                }\n\n                if ($method->getNumberOfParameters() > 0) {\n                    throw new InvalidDataProviderException(\n                        sprintf(\n                            'Data Provider method %s::%s() expects an argument',\n                            $className,\n                            $methodName,\n                        ),\n                    );\n                }\n\n                /** @phpstan-ignore staticMethod.dynamicName */\n                $data = $className::$methodName();\n\n                if (!is_iterable($data)) {\n                    throw new InvalidDataProviderException(\n                        sprintf(\n                            'Data Provider method %s::%s() does not return an iterable',\n                            $className,\n                            $methodName,\n                        ),","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Metadata/Api/DataProvider.php#L131-L167","documentation":"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.","triggerScenarios":"A provider method with a signature like 'public static function provideCases(string $context): array' referenced through @dataProvider.","commonSituations":"Providers that were originally helper methods taking arguments; refactorings that injected configuration parameters into a previously parameterless provider.","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"],"exampleFix":"// before\npublic static function provideCases(int $count): array\n{\n    return array_fill(0, $count, [1]);\n}\n\n// after\npublic static function provideCases(): array\n{\n    $count = 3;\n\n    return array_fill(0, $count, [1]);\n}","handlingStrategy":"validation","validationCode":"$method = new ReflectionMethod($testClass, 'provideCases');\n\nif ($method->getNumberOfParameters() > 0) {\n    // refactor to a zero-parameter provider before running\n}","typeGuard":"function isValidDataProvider(ReflectionMethod $method): bool\n{\n    return $method->isPublic()\n        && $method->isStatic()\n        && $method->getNumberOfParameters() === 0;\n}","tryCatchPattern":null,"preventionTips":["Keep providers parameterless; resolve configuration inside the method body","Review provider signatures when refactoring helpers into providers"],"tags":["phpunit","data-provider","method-signature","reflection"],"backgroundTag":"provider-method-with-parameters","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}