Update parsing expectation

This commit is contained in:
Andrea Marco Sartori 2022-11-17 23:53:54 +10:00
parent da7b20e489
commit bb3baca8f5

View File

@ -24,14 +24,22 @@
|
*/
expect()->extend('toParseTo', function (array $parsed) {
$actual = [];
expect()->extend('toParseTo', function (array $expected) {
$actual = $itemsCount = [];
foreach ($this->value as $key => $value) {
$actual[$key] = $value;
foreach ($this->value as $parsedKey => $parsedValue) {
$itemsCount[$parsedKey] = empty($itemsCount[$parsedKey]) ? 1 : $itemsCount[$parsedKey] + 1;
// the following match is required as we may deal with parsed values that are arrays
// and unpacking a parsed value that is an array may lead to unexpected results
$actual[$parsedKey] = match ($itemsCount[$parsedKey]) {
1 => $parsedValue,
2 => [$actual[$parsedKey], $parsedValue],
default => [...$actual[$parsedKey], $parsedValue],
};
}
expect($actual)->toBe($parsed);
expect($actual)->toBe($expected);
});
/*