{"record":{"id":"b06e8c6e95ca1f88","repo":"sebastianbergmann/phpunit","slug":"data-provider-method-s-s-does-not-return-an-i","errorCode":null,"errorMessage":"Data Provider method %s::%s() does not return an iterable","messagePattern":"Data Provider method (.+?)::(.+?)\\(\\) does not return an iterable","errorType":"exception","errorClass":"InvalidDataProviderException","httpStatus":null,"severity":"error","filePath":"src/Metadata/Api/DataProvider.php","lineNumber":162,"sourceCode":"                        ),\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                        ),\n                    );\n                }\n            } catch (Throwable $e) {\n                Event\\Facade::emitter()->dataProviderMethodFinished(\n                    $testMethodValueObject,\n                    ...$methodsCalled,\n                );\n\n                throw InvalidDataProviderException::forException($e, $providerLabel);\n            }\n\n            try {\n                foreach ($data as $key => $value) {","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Metadata/Api/DataProvider.php#L144-L180","documentation":"Thrown after invoking the provider method when its return value is not iterable (is_iterable() check fails). Providers must return an array or a Traversable (e.g. generator, ArrayIterator) whose entries are the argument sets for each test run.","triggerScenarios":"A provider typed/returning null, a scalar, or an object that does not implement Traversable (e.g. 'public static function provideCases(): ?string' or one that conditionally returns null).","commonSituations":"Generators with a bug that makes them return null on some path; providers returning a custom collection object instead of an array; early returns left in during refactoring.","solutions":["Change the provider to always return an array or a generator","Replace early 'return null/void' paths with 'return []' or 'yield from []'","If returning a custom collection, convert it with ->toArray() before returning"],"exampleFix":"// before\npublic static function provideCases(): ?array\n{\n    if (!extension_loaded('intl')) {\n        return null; // -> InvalidDataProviderException\n    }\n\n    return [[1], [2]];\n}\n\n// after\npublic static function provideCases(): array\n{\n    if (!extension_loaded('intl')) {\n        return [];\n    }\n\n    return [[1], [2]];\n}","handlingStrategy":"validation","validationCode":"// Guard inside the provider itself so consumers always receive an array\npublic static function provideCases(): array\n{\n    $data = self::buildCases(); // may return null on unsupported setups\n\n    return is_iterable($data) ? iterator_to_array($data) : [];\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare an explicit ': array' or ': Generator' return type on every provider","Never let a provider return null; use 'return []' for empty datasets","Convert custom collections with ->toArray() before returning them"],"tags":["phpunit","data-provider","return-type","iterable"],"backgroundTag":"data-provider-invalid-return","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}