{"record":{"id":"ba4aecbaa877c10b","repo":"sebastianbergmann/phpunit","slug":"data-set-s-provided-by-s-is-invalid-expected-ar","errorCode":null,"errorMessage":"Data set %s provided by %s is invalid, expected array but got %s","messagePattern":"Data set (.+?) provided by (.+?) is invalid, expected array but got (.+?)","errorType":"exception","errorClass":"InvalidDataProviderException","httpStatus":null,"severity":"error","filePath":"src/Metadata/Api/DataProvider.php","lineNumber":197,"sourceCode":"            try {\n                foreach ($data as $key => $value) {\n                    if (!is_int($key) && !is_string($key)) {\n                        throw new InvalidDataProviderException(\n                            sprintf(\n                                'The key must be an integer or a string, %s given',\n                                get_debug_type($key),\n                            ),\n                        );\n                    }\n\n                    if ($key === '') {\n                        throw new InvalidDataProviderException(\n                            'The key must not be an empty string',\n                        );\n                    }\n\n                    if (!is_array($value)) {\n                        throw new InvalidDataProviderException(\n                            sprintf(\n                                'Data set %s provided by %s is invalid, expected array but got %s',\n                                $this->formatKey($key),\n                                $providerLabel,\n                                get_debug_type($value),\n                            ),\n                        );\n                    }\n\n                    if ($validateArgumentCount && $testMethodNumberOfParameters < count($value)) {\n                        $this->triggerWarningForArgumentCount(\n                            $testMethod,\n                            $this->formatKey($key),\n                            $providerLabel,\n                            count($value),\n                            $testMethodNumberOfParameters,\n                        );\n                    }","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Metadata/Api/DataProvider.php#L179-L215","documentation":"PHPUnit called the data provider method named in your #[DataProvider] or #[DataProviderExternal] attribute and validated each data set it returned. Every value in a provider's iterable must be a plain array whose elements are passed as arguments to the test method. This error names the offending data set key, the provider (Class::method), and the actual type received instead of an array.","triggerScenarios":"A #[DataProvider('provider')] method returns an iterable containing at least one non-array value: return ['foo', 'bar']; (list of strings instead of list of argument arrays), yield 'user' => $userObject; (bare object row), or a generator that yields scalars.","commonSituations":"Providers migrated from frameworks where rows are single values; yield $key => $value instead of yield $key => [$value]; providers built from json_decode()/fixture files whose rows decode to scalars or objects; refactoring a single-parameter test and forgetting to wrap values.","solutions":["Open the provider named in the message and jump to the data set key it reports (\"key\" or #index).","Wrap each row in an array so it maps onto test method parameters: return [[1, 2], [3, 4]]; or yield 'name' => [$value].","If the test takes one parameter, keep each row a one-element array: [['hello'], ['world']].","Re-run with --filter <testMethodName> to verify only this provider is affected."],"exampleFix":"// before\npublic static function provider(): array\n{\n    return ['hello', 'world'];\n}\n\n// after\npublic static function provider(): array\n{\n    return [['hello'], ['world']];\n}","handlingStrategy":"validation","validationCode":"// Meta-test: assert provider shape before PHPUnit consumes it\npublic function testProviderYieldsArgumentArrays(): void\n{\n    foreach (MyTest::provider() as $key => $value) {\n        self::assertIsArray($value, sprintf('Data set %s is not an argument array', (string) $key));\n    }\n}","typeGuard":"function isValidProviderData(mixed $data): bool\n{\n    if (!is_iterable($data)) {\n        return false;\n    }\n\n    foreach ($data as $key => $value) {\n        if ((!is_int($key) && !is_string($key)) || $key === '' || !is_array($value)) {\n            return false;\n        }\n    }\n\n    return true;\n}","tryCatchPattern":null,"preventionTips":["Declare provider return types as array<int|string, array<mixed>> so PHPStan can flag scalar rows.","Write one meta-test per provider asserting every row is an array with int/non-empty-string keys.","Run vendor/bin/phpunit --list-tests in CI: it enumerates every provider and fails fast on malformed data."],"tags":["phpunit","php","data-provider","tests"],"backgroundTag":"data-provider-invalid-dataset","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}