fix types

This commit is contained in:
Fabio Ivona
2022-08-29 14:04:47 +02:00
parent 42ceddf374
commit 38a82cd142
2 changed files with 14 additions and 4 deletions

View File

@ -710,11 +710,11 @@ final class Expectation
/** /**
* Asserts that the value array matches the given array subset. * Asserts that the value array matches the given array subset.
* *
* @param iterable<int|string, mixed>|object $array * @param iterable<int|string, mixed> $array
* *
* @return Expectation<TValue> * @return Expectation<TValue>
*/ */
public function toMatchArray(array|object $array): Expectation public function toMatchArray(iterable $array): Expectation
{ {
if (is_object($this->value) && method_exists($this->value, 'toArray')) { if (is_object($this->value) && method_exists($this->value, 'toArray')) {
$valueAsArray = $this->value->toArray(); $valueAsArray = $this->value->toArray();
@ -747,11 +747,11 @@ final class Expectation
* Asserts that the value object matches a subset * Asserts that the value object matches a subset
* of the properties of an given object. * of the properties of an given object.
* *
* @param object|array<string, mixed> $object * @param iterable<string, mixed> $object
* *
* @return Expectation<TValue> * @return Expectation<TValue>
*/ */
public function toMatchObject(object|array $object): Expectation public function toMatchObject(iterable $object): Expectation
{ {
foreach ((array) $object as $property => $value) { foreach ((array) $object as $property => $value) {
if (!is_object($this->value) && !is_string($this->value)) { if (!is_object($this->value) && !is_string($this->value)) {

View File

@ -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 () { test('failures', function () {
expect($this->user)->toMatchObject([ expect($this->user)->toMatchObject([
'name' => 'Not the same name', 'name' => 'Not the same name',