{"record":{"id":"73a89338a41c3774","repo":"pestphp/pest","slug":"the-test-expects-d-argument-s-but-the-dataset","errorCode":null,"errorMessage":"The test expects [%d] argument(s), but the dataset only provides [%d].","messagePattern":"The test expects \\[(.+?)\\] argument\\(s\\), but the dataset only provides \\[(.+?)\\]\\.","errorType":"exception","errorClass":"DatasetArgumentsMismatch","httpStatus":null,"severity":"error","filePath":"src/Concerns/Testable.php","lineNumber":498,"sourceCode":"        $testReflection = new ReflectionFunction($underlyingTest);\n        $requiredParametersCount = $testReflection->getNumberOfRequiredParameters();\n        $suppliedParametersCount = count($arguments);\n\n        $datasetParameterNames = array_keys($arguments);\n        $testParameterNames = array_map(\n            fn (ReflectionParameter $reflectionParameter): string => $reflectionParameter->getName(),\n            array_filter($testReflection->getParameters(), fn (ReflectionParameter $reflectionParameter): bool => ! $reflectionParameter->isOptional()),\n        );\n\n        if (array_diff($testParameterNames, $datasetParameterNames) === []) {\n            return;\n        }\n\n        if (isset($testParameterNames[0]) && $suppliedParametersCount >= $requiredParametersCount) {\n            return;\n        }\n\n        throw new DatasetArgumentsMismatch($requiredParametersCount, $suppliedParametersCount);\n    }\n\n    /**\n     * @throws Throwable\n     */\n    private function __callClosure(Closure $closure, array $arguments): mixed\n    {\n        return ExceptionTrace::ensure(fn (): mixed => call_user_func_array(Closure::bind($closure, $this, $this::class), $arguments));\n    }\n\n    public function preset(): Preset\n    {\n        return new Preset;\n    }\n\n    #[PostCondition]\n    protected function __MarkTestIncompleteIfSnapshotHaveChanged(): void\n    {","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/pestphp/pest/blob/1af74a215c3a89bc7a44fc6f9322e369eaad2423/src/Concerns/Testable.php#L480-L516","documentation":"Before executing a dataset-driven test, Pest reflects on the test closure and counts its required parameters, then compares that with the number of values the dataset row supplies (also matching parameter names when the dataset uses named keys). If the row provides fewer values than required and the names do not cover the gap, Pest aborts the test with DatasetArgumentsMismatch instead of letting PHP raise an ArgumentCountError mid-test.","triggerScenarios":"it('adds', function (int $a, int $b) { ... })->with([[1]]); a named dataset row whose keys do not match the closure parameter names (['x' => 1] vs parameter $a) while also being short; a dataset closure returning a scalar that Pest wraps into a single-element array while the test expects two parameters.","commonSituations":"Adding a parameter to an existing test signature and forgetting to update every dataset row; datasets sourced from CSV/JSON/YAML files with missing columns; mixing named and positional datasets; refactoring datasets into generators that yield fewer fields.","solutions":["Make every dataset row supply all required parameters: ->with([[1, 2]]).","Give the added parameters defaults so they become optional: function (int $a, int $b = 0).","Use named keys in the dataset that exactly match the closure parameter names (['a' => 1, 'b' => 2]).","If a dataset closure returns an array meant to be spread as multiple arguments, wrap it so Pest spreads rather than wraps: ->with(fn () => [[1, 2]])."],"exampleFix":"// before\nit('adds', function (int $a, int $b) {\n    expect($a + $b)->toBe(3);\n})->with([[1]]);\n// after\nit('adds', function (int $a, int $b) {\n    expect($a + $b)->toBe(3);\n})->with([[1, 2]]);","handlingStrategy":"validation","validationCode":"// sanity-check dataset rows against the test signature before running:\n$required = (new ReflectionFunction($testClosure))->getNumberOfRequiredParameters();\nforeach ($dataset as $row) {\n    $row = is_array($row) ? $row : [$row];\n    if (count($row) < $required && array_diff($paramNames, array_keys($row)) !== []) {\n        throw new RuntimeException('Dataset row provides '.count($row).\" args, test requires {$required}\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When adding a parameter to a dataset-driven test, update every row in the same commit.","Prefer named dataset keys identical to the closure parameter names — Pest matches names before counts.","For file-based datasets (csv/json), add a quick row-width assertion in a helper test."],"tags":["pest","dataset","arguments","reflection","test-signature"],"backgroundTag":"argument-count-mismatch","analyzedSha":"1af74a215c3a89bc7a44fc6f9322e369eaad2423","analyzedAt":"2026-08-21T02:16:38.132Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}