Skip to content

Commit f441aec

Browse files
committed
Structure::merge() without otherItems it merges by overwriting
1 parent d00e944 commit f441aec

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Schema/Elements/Structure.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function merge(mixed $value, mixed $base): mixed
130130
}
131131

132132
if (is_array($value) && is_array($base)) {
133-
$index = 0;
133+
$index = $this->otherItems === null ? null : 0;
134134
foreach ($value as $key => $val) {
135135
if ($key === $index) {
136136
$base[] = $val;

tests/Schema/Expect.structure.phpt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,15 @@ test('with indexed item', function () {
156156
$processor->process($schema, ['key1' => 'newval', 'newval3']),
157157
);
158158

159-
checkValidationErrors(function () use ($processor, $schema) {
160-
$processor->processMultiple($schema, [['key1' => 'newval', 'newval3'], ['key2' => 'newval', 'newval4']]);
161-
}, ["Unexpected item '1'."]);
159+
Assert::equal(
160+
(object) [
161+
'key1' => 'newval',
162+
'key2' => 'newval',
163+
'newval4',
164+
'arr' => [],
165+
],
166+
$processor->processMultiple($schema, [['key1' => 'newval', 'newval3'], ['key2' => 'newval', 'newval4']]),
167+
);
162168
});
163169

164170

0 commit comments

Comments
 (0)