[DependencyInjection] append new elements for prototype nodes without a key attribute
This commit is contained in:
parent
0b8fef2347
commit
c7ef8d98d6
@ -318,6 +318,12 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
|
||||
}
|
||||
|
||||
foreach ($rightSide as $k => $v) {
|
||||
// prototype, and key is irrelevant, so simply append the element
|
||||
if (null !== $this->prototype && null === $this->keyAttribute) {
|
||||
$leftSide[] = $v;
|
||||
continue;
|
||||
}
|
||||
|
||||
// no conflict
|
||||
if (!array_key_exists($k, $leftSide)) {
|
||||
if (!$this->allowNewKeys) {
|
||||
|
@ -15,9 +15,7 @@ class MergeTest extends \PHPUnit_Framework_TestCase
|
||||
$tree = $tb
|
||||
->root('root', 'array')
|
||||
->node('foo', 'scalar')
|
||||
->merge()
|
||||
->denyOverwrite()
|
||||
->end()
|
||||
->cannotBeOverwritten()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
@ -42,12 +40,12 @@ class MergeTest extends \PHPUnit_Framework_TestCase
|
||||
->node('foo', 'scalar')->end()
|
||||
->node('bar', 'scalar')->end()
|
||||
->node('unsettable', 'array')
|
||||
->merge()->allowUnset()->end()
|
||||
->canBeUnset()
|
||||
->node('foo', 'scalar')->end()
|
||||
->node('bar', 'scalar')->end()
|
||||
->end()
|
||||
->node('unsetted', 'array')
|
||||
->merge()->allowUnset()->end()
|
||||
->canBeUnset()
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
@ -145,4 +143,28 @@ class MergeTest extends \PHPUnit_Framework_TestCase
|
||||
)
|
||||
), $tree->merge($a, $b));
|
||||
}
|
||||
|
||||
public function testPrototypeWithoutAKeyAttribute()
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
|
||||
$tree = $tb
|
||||
->root('config', 'array')
|
||||
->node('append_elements', 'array')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
;
|
||||
|
||||
$a = array(
|
||||
'append_elements' => array('a', 'b'),
|
||||
);
|
||||
|
||||
$b = array(
|
||||
'append_elements' => array('c', 'd'),
|
||||
);
|
||||
|
||||
$this->assertEquals(array('append_elements' => array('a', 'b', 'c', 'd')), $tree->merge($a, $b));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user