{"record":{"id":"cdab1c7b01a9683c","repo":"pestphp/pest","slug":"failed-asserting-that-an-array-has-the-key-key","errorCode":null,"errorMessage":"Failed asserting that an array has the key [$key]","messagePattern":"Failed asserting that an array has the key \\[\\$key\\]","errorType":"exception","errorClass":"ExpectationFailedException","httpStatus":null,"severity":"error","filePath":"src/Mixins/Expectation.php","lineNumber":547,"sourceCode":"     */\n    public function toHaveKey(string|int $key, mixed $value = new Any, string $message = ''): self\n    {\n        if (is_object($this->value) && method_exists($this->value, 'toArray')) {\n            $array = $this->value->toArray();\n        } else {\n            $array = (array) $this->value;\n        }\n\n        try {\n            Assert::assertTrue(Arr::has($array, $key));\n\n            /* @phpstan-ignore-next-line */\n        } catch (ExpectationFailedException $exception) {\n            if ($message === '') {\n                $message = \"Failed asserting that an array has the key [$key]\";\n            }\n\n            throw new ExpectationFailedException($message, $exception->getComparisonFailure());\n        }\n\n        if (! $value instanceof Any) {\n            Assert::assertEquals($value, Arr::get($array, $key), $message);\n        }\n\n        return $this;\n    }\n\n    /**\n     * @param  array<int, int|string|array<array-key, mixed>>  $keys\n     * @return self<TValue>\n     */\n    public function toHaveKeys(array $keys, string $message = ''): self\n    {\n        foreach ($keys as $k => $key) {\n            if (is_array($key)) {\n                $this->toHaveKeys(array_keys(Arr::dot($key, $k.'.')), $message);","sourceCodeStart":529,"sourceCodeEnd":565,"githubUrl":"https://github.com/pestphp/pest/blob/1af74a215c3a89bc7a44fc6f9322e369eaad2423/src/Mixins/Expectation.php#L529-L565","documentation":"Error \"Failed asserting that an array has the key [$key]\" thrown in pestphp/pest.","triggerScenarios":"Thrown at src/Mixins/Expectation.php:547 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1af74a215c3a89bc7a44fc6f9322e369eaad2423","analyzedAt":"2026-08-21T02:16:38.132Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}