{"record":{"id":"2d4d84cee9eba3b0","repo":"sebastianbergmann/phpunit","slug":"empty-data-set-provided-by-data-provider","errorCode":null,"errorMessage":"Empty data set provided by data provider","messagePattern":"Empty data set provided by data provider","errorType":"exception","errorClass":"InvalidDataProviderException","httpStatus":null,"severity":"error","filePath":"src/Metadata/Api/DataProvider.php","lineNumber":360,"sourceCode":"                        ),\n                    );\n                }\n\n                $result[$key] = new ProvidedData($providerLabel, $value);\n            }\n        }\n\n        Event\\Facade::emitter()->dataProviderMethodFinished(\n            $testMethodValueObject,\n            ...$methodsCalled,\n        );\n\n        if ($result === []) {\n            if ($skipWhenEmpty) {\n                return [];\n            }\n\n            throw new InvalidDataProviderException(\n                'Empty data set provided by data provider',\n            );\n        }\n\n        return $result;\n    }\n\n    /**\n     * @return array<ProvidedData>\n     */\n    private function dataProvidedByMetadata(ReflectionMethod $testMethod, MetadataCollection $testWith): array\n    {\n        $result                       = [];\n        $testMethodNumberOfParameters = $testMethod->getNumberOfParameters();\n        $testMethodIsNonVariadic      = !$testMethod->isVariadic();\n        $autoIncrementKey             = 0;\n\n        foreach ($testWith as $i => $_testWith) {","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Metadata/Api/DataProvider.php#L342-L378","documentation":"After collecting data from every provider attached to the test method, PHPUnit ended up with zero data sets. An empty result is treated as an authoring error: the test declares a provider that delivers nothing to run. Providers whose attribute sets skipWhenEmpty: true are exempt — the test is then skipped instead of erroring.","triggerScenarios":"A #[DataProvider] or #[DataProviderClosure] provider returns [] or an empty generator — fixture glob matches nothing, a query returns no rows, a filtered dataset is empty — and the attribute does not set skipWhenEmpty: true.","commonSituations":"Environment-dependent providers (no fixtures in CI, empty test database); a wrong glob path silently matching nothing; a dataset builder bug that always returns [].","solutions":["Fix the provider so it produces the expected data (check the glob path, query, fixtures).","If 'no data' is a legitimate state, mark the attribute #[DataProvider('provider', skipWhenEmpty: true)] so the test skips instead of erroring.","Add a meta-test asserting the provider yields at least one row in your environment."],"exampleFix":"// before\n#[DataProvider('provider')]\n\n// after (when an empty data set is acceptable)\n#[DataProvider('provider', skipWhenEmpty: true)]","handlingStrategy":"validation","validationCode":"// Meta-test: provider must yield at least one row in this environment\nself::assertNotSame([], MyTest::provider(), 'Provider unexpectedly empty; check fixtures/glob paths');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mark legitimately-optional providers with #[DataProvider('provider', skipWhenEmpty: true)].","Make glob/query paths explicit and fail loudly when they resolve to nothing.","Assert provider non-emptiness in a meta-test so silent environment differences surface early."],"tags":["phpunit","php","data-provider","empty-dataset"],"backgroundTag":"data-provider-empty-dataset","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}