feat: casts to array using toArray

This commit is contained in:
Nuno Maduro
2020-11-23 21:37:35 +01:00
parent 7bea51fe09
commit 3fd24d96d3

View File

@ -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);