{"record":{"id":"2967f534dcbb62fc","repo":"hamcrest/hamcrest-php","slug":"assertthat-requires-one-to-three-arguments","errorCode":null,"errorMessage":"assertThat() requires one to three arguments","messagePattern":"assertThat\\(\\) requires one to three arguments","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"hamcrest/Hamcrest/MatcherAssert.php","lineNumber":68,"sourceCode":"                self::$_count++;\n                if ($args[1] instanceof Matcher) {\n                    self::doAssert('', $args[0], $args[1]);\n                } elseif (!$args[1]) {\n                    throw new AssertionError($args[0]);\n                }\n                break;\n\n            case 3:\n                self::$_count++;\n                self::doAssert(\n                    $args[0],\n                    $args[1],\n                    Util::wrapValueWithIsEqual($args[2])\n                );\n                break;\n\n            default:\n                throw new \\InvalidArgumentException('assertThat() requires one to three arguments');\n        }\n    }\n\n    /**\n     * Returns the number of assertions performed.\n     *\n     * @return int\n     */\n    public static function getCount(): int\n    {\n        return self::$_count;\n    }\n\n    /**\n     * Resets the number of assertions performed to zero.\n     */\n    public static function resetCount(): void\n    {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/hamcrest/hamcrest-php/blob/aa726aeff92ee86f82a89ca30dc0af9e01fb3539/hamcrest/Hamcrest/MatcherAssert.php#L50-L86","documentation":"MatcherAssert::assertThat() only supports signatures with one, two, or three arguments; any other argument count (0, 4+) falls into the default branch and throws InvalidArgumentException. It is a guard against calling a variadic-style assertion with the wrong arity.","triggerScenarios":"Calling assertThat() with zero arguments, or four or more arguments (e.g. assertThat($desc, $actual, $matcher, $extra)).","commonSituations":"Refactoring signatures and leaving a stray extra argument; dynamic call_user_func_array with an unexpected-sized args array; forgetting the actual value entirely.","solutions":["Call assertThat with 1-3 args: (matcher), (actual, matcher), or (reason, actual, matcher)","Remove extra arguments and assert them separately","If args are dynamic, validate count($args) between 1 and 3 before calling"],"exampleFix":"// before\nassertThat($reason, $actual, $matcher, $extra);\n// after\nassertThat($reason, $actual, $matcher);\nassertThat($extra, anything());","handlingStrategy":"validation","validationCode":"if (count($args) < 1 || count($args) > 3) {\n    throw new PreconditionException('assertThat needs 1-3 args');\n}","typeGuard":null,"tryCatchPattern":"try {\n    assertThat(...$args);\n} catch (\\InvalidArgumentException $e) {\n    if ($e->getMessage() !== 'assertThat() requires one to three arguments') throw $e;\n    throw new BadMethodCallException('Wrong assertThat arity: '.count($args));\n}","preventionTips":["Use the three canonical signatures only: (matcher), (actual, matcher), (reason, actual, matcher)","Avoid call_user_func_array with unvalidated arg arrays","Let IDE autocomplete pick the overload instead of manual argument lists"],"tags":["php","hamcrest","argument-count","assertion"],"backgroundTag":"missing-required-argument","analyzedSha":"aa726aeff92ee86f82a89ca30dc0af9e01fb3539","analyzedAt":"2026-09-15T04:07:57.177Z","contentChangedAt":"2026-09-15T04:07:57.177Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}