8000 Added test case and comment for array union · symfony/symfony@55368f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 55368f8

Browse files
committed
Added test case and comment for array union
1 parent c83aa8c commit 55368f8

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
161161
throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
162162
}
163163

164-
$data += $refValue;
164+
$data += $refValue; // array union
165165
} else {
166166
if (isset($values['value']) && $values['value'] !== '') {
167167
$value = $values['value'];
@@ -183,12 +183,12 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
183183
throw new ParseException('Merge items must be arrays.', $this->getRealCurrentLineNb() + 1, $parsedItem);
184184
}
185185

186-
$data += $parsedItem;
186+
$data += $parsedItem; // array union
187187
}
188188
} else {
189189
// If the value associated with the key is a single mapping node, each of its key/value pairs is inserted into the
190190
// current mapping, unless the key already exists in it.
191-
$data += $parsed;
191+
$data += $parsed; // array union
192192
}
193193
}
194194
} elseif (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) {

src/Symfony/Component/Yaml/Tests/Fixtures/sfMergeKey.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ yaml: |
1010
a: Steve
1111
b: Clark
1212
c: Brian
13+
e: notnull
1314
bar:
1415
a: before
1516
d: other
17+
e: ~
1618
<<: *foo
1719
b: new
1820
x: Oren
@@ -46,13 +48,13 @@ yaml: |
4648
<<: *nestedref
4749
php: |
4850
array(
49-
'foo' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian'),
50-
'bar' => array('a' => 'before', 'd' => 'other', 'b' => 'new', 'c' => array('foo' => 'bar', 'bar' => 'foo'), 'x' => 'Oren'),
51+
'foo' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull'),
52+
'bar' => array('a' => 'before', 'd' => 'other', 'e' => null, 'b' => 'new', 'c' => array('foo' => 'bar', 'bar' => 'foo'), 'x' => 'Oren'),
5153
'duplicate' => array('foo' => 'bar'),
5254
'foo2' => array('a' => 'Ballmer'),
5355
'ding' => array('fi', 'fei', 'fo', 'fam'),
54-
'check' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam', 'isit' => 'tested'),
55-
'head' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam'),
56+
'check' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam', 'isit' => 'tested'),
57+
'head' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam'),
5658
'taz' => array('a' => 'Steve', 'w' => array('p' => 1234)),
5759
'nested' => array('a' => 'Steve', 'w' => array('p' => 12345), 'd' => 'Doug', 'z' => array('p' => 12345))
5860
)

0 commit comments

Comments
 (0)
0