mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
toMatchArray/Object wrong field fix
The functions toMatchArray and toMatchObject indicate that the wrong field is mismatching from the second loop on because the 'message' is overwritten and taken into the following loop. This patch creates a $second_message for the second test (value test) to keep the error message correct.
This commit is contained in:
@ -780,17 +780,16 @@ final class Expectation
|
||||
}
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
$message = '';
|
||||
Assert::assertArrayHasKey($key, $valueAsArray, $message);
|
||||
|
||||
if ($message === '') {
|
||||
$message = sprintf(
|
||||
$second_message = $message !== '' ? $message : sprintf(
|
||||
'Failed asserting that an array has a key %s with the value %s.',
|
||||
$this->export($key),
|
||||
$this->export($valueAsArray[$key]),
|
||||
);
|
||||
}
|
||||
|
||||
Assert::assertEquals($value, $valueAsArray[$key], $message);
|
||||
Assert::assertEquals($value, $valueAsArray[$key], $second_message);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -815,15 +814,14 @@ final class Expectation
|
||||
/* @phpstan-ignore-next-line */
|
||||
$propertyValue = $this->value->{$property};
|
||||
|
||||
if ($message === '') {
|
||||
$message = sprintf(
|
||||
$second_message = $message !== '' ? $message : sprintf(
|
||||
'Failed asserting that an object has a property %s with the value %s.',
|
||||
$this->export($property),
|
||||
$this->export($propertyValue),
|
||||
);
|
||||
}
|
||||
|
||||
Assert::assertEquals($value, $propertyValue, $message);
|
||||
Assert::assertEquals($value, $propertyValue, $second_message);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
Reference in New Issue
Block a user