{"record":{"id":"b10179f06c5acdd5","repo":"sebastianbergmann/phpunit","slug":"data-provider-method-s-s-is-not-static","errorCode":null,"errorMessage":"Data Provider method %s::%s() is not static","messagePattern":"Data Provider method (.+?)::(.+?)\\(\\) is not static","errorType":"exception","errorClass":"InvalidDataProviderException","httpStatus":null,"severity":"error","filePath":"src/Metadata/Api/DataProvider.php","lineNumber":139,"sourceCode":"                            $_dataProvider->methodName(),\n                            $testMethod->getDeclaringClass()->getName(),\n                            $testMethod->getName(),\n                        ),\n                    );\n                }\n\n                if (!$method->isPublic()) {\n                    throw new InvalidDataProviderException(\n                        sprintf(\n                            '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","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Metadata/Api/DataProvider.php#L121-L157","documentation":"Thrown while resolving a data provider when the referenced method exists and is public but not static. PHPUnit calls providers as $className::$methodName() (static late binding) before any test instance exists, so ReflectionMethod::isStatic() is required.","triggerScenarios":"Declaring the provider as a public instance method: 'public function provideCases(): array' and referencing it via #[DataProvider('provideCases')].","commonSituations":"Converting older tests where providers were instance methods; IDE refactorings dropping 'static'; copying providers between instance-based helper classes.","solutions":["Add the 'static' keyword to the provider method"],"exampleFix":"// before\n#[DataProvider('provideCases')]\npublic function testX(int $n): void { ... }\n\npublic function provideCases(): array { ... }\n\n// after\n#[DataProvider('provideCases')]\npublic function testX(int $n): void { ... }\n\npublic static function provideCases(): array { ... }","handlingStrategy":"validation","validationCode":"$method = new ReflectionMethod($testClass, 'provideCases');\n\nif (!$method->isStatic()) {\n    // add 'static' before running the suite\n}","typeGuard":"function isValidDataProvider(ReflectionMethod $method): bool\n{\n    return $method->isPublic()\n        && $method->isStatic()\n        && $method->getNumberOfParameters() === 0;\n}","tryCatchPattern":null,"preventionTips":["Use snippets/templates that emit 'public static function' for providers","Verify provider shape with isValidDataProvider() in custom test loaders"],"tags":["phpunit","data-provider","static-method","reflection"],"backgroundTag":"non-static-provider-method","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}