{"record":{"id":"f302a2bb2d368a91","repo":"sebastianbergmann/phpunit","slug":"data-provider-method-s-s-is-not-public","errorCode":null,"errorMessage":"Data Provider method %s::%s() is not public","messagePattern":"Data Provider method (.+?)::(.+?)\\(\\) is not public","errorType":"exception","errorClass":"InvalidDataProviderException","httpStatus":null,"severity":"error","filePath":"src/Metadata/Api/DataProvider.php","lineNumber":129,"sourceCode":"            try {\n                $method     = new ReflectionMethod($_dataProvider->className(), $_dataProvider->methodName());\n                $className  = $_dataProvider->className();\n                $methodName = $_dataProvider->methodName();\n\n                if (Test::isTestMethod($method)) {\n                    Event\\Facade::emitter()->testRunnerTriggeredPhpunitWarning(\n                        sprintf(\n                            'Method %s::%s() used by test method %s::%s() is also a test method',\n                            $_dataProvider->className(),\n                            $_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","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Metadata/Api/DataProvider.php#L111-L147","documentation":"Thrown while resolving a @dataProvider annotation/attribute when the referenced provider method exists but is not public. PHPUnit invokes provider methods statically from the framework, so ReflectionMethod::isPublic() is enforced and non-public providers are rejected with InvalidDataProviderException.","triggerScenarios":"Declaring the provider as protected or private: '#[DataProvider('provideCases')] private static function provideCases(): ...' and running the test.","commonSituations":"Refactoring tests and changing provider visibility to reduce the public API of test classes; copy-pasting providers from classes where they were protected utilities.","solutions":["Change the provider method's visibility to public","Keep the visibility but move the data generation into a public static provider that delegates"],"exampleFix":"// before\n#[DataProvider('provideCases')]\npublic function testX(int $n): void { ... }\n\nprotected static 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->isPublic()) {\n    // make it public 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":["Standardize provider signatures as 'public static function ...()' with zero parameters","Add a lint/CI check or PHPStan rule asserting provider visibility"],"tags":["phpunit","data-provider","visibility","reflection"],"backgroundTag":"non-public-provider-method","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}