diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 8c9dd99d..61d5bf6e 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -710,11 +710,11 @@ final class Expectation /** * Asserts that the value array matches the given array subset. * - * @param iterable|object $array + * @param iterable $array * * @return Expectation */ - public function toMatchArray(array|object $array): Expectation + public function toMatchArray(iterable $array): Expectation { if (is_object($this->value) && method_exists($this->value, 'toArray')) { $valueAsArray = $this->value->toArray(); @@ -747,11 +747,11 @@ final class Expectation * Asserts that the value object matches a subset * of the properties of an given object. * - * @param object|array $object + * @param iterable $object * * @return Expectation */ - public function toMatchObject(object|array $object): Expectation + public function toMatchObject(iterable $object): Expectation { foreach ((array) $object as $property => $value) { if (!is_object($this->value) && !is_string($this->value)) { diff --git a/tests/Features/Expect/toMatchObject.php b/tests/Features/Expect/toMatchObject.php index fd2c358b..a4394e4c 100644 --- a/tests/Features/Expect/toMatchObject.php +++ b/tests/Features/Expect/toMatchObject.php @@ -17,6 +17,16 @@ test('pass', function () { ]); }); +test('pass with class', function () { + expect(new class() { + public $name = 'Nuno'; + public $email = 'enunomaduro@gmail.com'; + })->toMatchObject([ + 'name' => 'Nuno', + 'email' => 'enunomaduro@gmail.com', + ]); +}); + test('failures', function () { expect($this->user)->toMatchObject([ 'name' => 'Not the same name',