Skip to content

Commit

Permalink
feat: casts to array using toArray
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Nov 23, 2020
1 parent 7bea51f commit 3fd24d9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 3fd24d9

Please sign in to comment.