diff --git a/src/Expectation.php b/src/Expectation.php index 00f87ffd1..68d0790df 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -412,7 +412,11 @@ public function toBeNull(): Expectation */ public function toHaveKey($key, $value = null): Expectation { - $array = (array) $this->value; + if (is_object($this->value) && method_exists($this->value, 'toArray')) { + $array = $this->value->toArray(); + } else { + $array = (array) $this->value; + } Assert::assertArrayHasKey($key, $array);