{"record":{"id":"1aa2076f80420c52","repo":"sebastianbergmann/phpunit","slug":"too-many-parameter-sets-given-d-out-of-d-expect","errorCode":null,"errorMessage":"Too many parameter sets given, %d out of %d expected parameter set%s %s been called.","messagePattern":"Too many parameter sets given, (.+?) out of (.+?) expected parameter set(.+?) (.+?) been called\\.","errorType":"exception","errorClass":"ExpectationFailedException","httpStatus":null,"severity":"error","filePath":"src/Framework/MockObject/Runtime/Rule/OrderedParameterSets.php","lineNumber":84,"sourceCode":"\n        $parameters      = array_shift($this->stack);\n        $this->applied[] = $parameters;\n\n        $parameters->apply($invocation);\n    }\n\n    /**\n     * Checks if the invocation $invocation matches the current rules. If it\n     * does the rule will get the invoked() method called which should check\n     * if an expectation is met.\n     *\n     * @throws ExpectationFailedException\n     */\n    public function verify(): void\n    {\n        if (count($this->applied) !== $this->numberOfConfiguredParameterSets &&\n            count($this->stack) > 0) {\n            throw new ExpectationFailedException(\n                sprintf(\n                    'Too many parameter sets given, %d out of %d expected parameter set%s %s been called.',\n                    count($this->applied),\n                    $this->numberOfConfiguredParameterSets,\n                    $this->numberOfConfiguredParameterSets !== 1 ? 's' : '',\n                    count($this->applied) !== 1 ? 'have' : 'has',\n                ),\n            );\n        }\n\n        foreach ($this->applied as $parameters) {\n            $parameters->verify();\n        }\n    }\n}\n","sourceCodeStart":66,"sourceCodeEnd":100,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Framework/MockObject/Runtime/Rule/OrderedParameterSets.php#L66-L100","documentation":"Despite its wording, this PHPUnit error fires when fewer calls arrived than configured: withParameterSetsInOrder(...) was given more parameter sets than the code under test consumed. OrderedParameterSets::verify() runs at mock-verification time; if parameter sets are still left on the stack (count($this->stack) > 0), it reports how many sets were actually used versus how many were configured. 'Too many parameter sets given' means the test over-specified the expected interaction, not that the code called too often.","triggerScenarios":"$mock->expects($this->any())->method('save')->withParameterSetsInOrder([$dtoA], [$dtoB]) while the code calls save() only once. The error appears after the test body, when PHPUnit verifies the mock: 1 out of 2 expected parameter sets has been called.","commonSituations":"An early return or exception in the SUT skipping later calls; tests written against an older flow that used to iterate twice; one branch of a conditional not exercised by the fixture; copy-pasted parameter sets left over from another test; fixtures shrinking so the loop body runs fewer times.","solutions":["Compare the two counts in the message: the first is how many sets were consumed, the second how many you configured — trust the consumed count.","Remove the unused parameter set(s), or fix the data/path so the code actually makes the remaining calls.","If some calls are conditional, split the expectation into separate matchers (one withParameterSetsInOrder per scenario) or use withParameterSetsInPartialOrder() with pinned sets for the calls that must happen at a given position.","Ensure expects() matches the real count (exactly(1) instead of any()) so leftover sets cannot hide.","If the skipped call reveals a real bug (missing second save), fix the production code path."],"exampleFix":"// before\n$repo->expects($this->any())->method('save')\n    ->withParameterSetsInOrder([$user], [$audit]);\n$service->register($user); // only saves $user, audit write is skipped\n\n// after: configure only the calls that actually happen\n$repo->expects($this->once())->method('save')\n    ->withParameterSetsInOrder([$user]);","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read the message as 'fewer calls than sets': keep sets and expects() count in sync.","Use expects(exactly(n)) with n sets so a shortfall always fails loudly and identifiably.","Delete parameter sets when you delete a call from the SUT; stale sets are the main cause.","Keep each test to one scenario — conditional second calls belong in a separate test with their own matcher."],"tags":["phpunit","mock","parameter-sets","verification"],"backgroundTag":"mock-parameter-set-mismatch","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}