diff --git a/src/Symfony/Component/DependencyInjection/Configuration/ArrayNode.php b/src/Symfony/Component/DependencyInjection/Configuration/ArrayNode.php index 1b9cbdfdc1..e5b75a5a0a 100644 --- a/src/Symfony/Component/DependencyInjection/Configuration/ArrayNode.php +++ b/src/Symfony/Component/DependencyInjection/Configuration/ArrayNode.php @@ -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) { diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Configuration/MergeTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Configuration/MergeTest.php index 0fab77cc11..64fc6da4ed 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Configuration/MergeTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Configuration/MergeTest.php @@ -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)); + } } \ No newline at end of file