Skip to content

Commit

Permalink
Structure::merge() without otherItems it merges by overwriting
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 6, 2024
1 parent d00e944 commit f441aec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Schema/Elements/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function merge(mixed $value, mixed $base): mixed
}

if (is_array($value) && is_array($base)) {
$index = 0;
$index = $this->otherItems === null ? null : 0;
foreach ($value as $key => $val) {
if ($key === $index) {
$base[] = $val;
Expand Down
12 changes: 9 additions & 3 deletions tests/Schema/Expect.structure.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,15 @@ test('with indexed item', function () {
$processor->process($schema, ['key1' => 'newval', 'newval3']),
);

checkValidationErrors(function () use ($processor, $schema) {
$processor->processMultiple($schema, [['key1' => 'newval', 'newval3'], ['key2' => 'newval', 'newval4']]);
}, ["Unexpected item '1'."]);
Assert::equal(
(object) [
'key1' => 'newval',
'key2' => 'newval',
'newval4',
'arr' => [],
],
$processor->processMultiple($schema, [['key1' => 'newval', 'newval3'], ['key2' => 'newval', 'newval4']]),
);
});


Expand Down

0 comments on commit f441aec

Please sign in to comment.