mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
fix types
This commit is contained in:
@ -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)) {
|
||||||
|
|||||||
@ -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',
|
||||||
|
|||||||
Reference in New Issue
Block a user