From 3fd24d96d3145dcebdb0aab40aa8b76faa8b6979 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 23 Nov 2020 21:37:35 +0100 Subject: [PATCH] feat: casts to array using `toArray` --- src/Expectation.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Expectation.php b/src/Expectation.php index 00f87ffd..68d0790d 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -412,7 +412,11 @@ final class 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);