4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Config\Tests\Definition;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17 class MergeTest extends TestCase
20 * @expectedException \Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException
22 public function testForbiddenOverwrite()
24 $tb = new TreeBuilder();
26 ->root('root', 'array')
28 ->node('foo', 'scalar')
29 ->cannotBeOverwritten()
47 public function testUnsetKey()
49 $tb = new TreeBuilder();
51 ->root('root', 'array')
53 ->node('foo', 'scalar')->end()
54 ->node('bar', 'scalar')->end()
55 ->node('unsettable', 'array')
58 ->node('foo', 'scalar')->end()
59 ->node('bar', 'scalar')->end()
62 ->node('unsetted', 'array')
64 ->prototype('scalar')->end()
73 'unsettable' => array(
83 'unsettable' => false,
84 'unsetted' => array('a', 'b'),
87 $this->assertEquals(array(
90 'unsettable' => false,
91 'unsetted' => array('a', 'b'),
92 ), $tree->merge($a, $b));
96 * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
98 public function testDoesNotAllowNewKeysInSubsequentConfigs()
100 $tb = new TreeBuilder();
102 ->root('config', 'array')
104 ->node('test', 'array')
105 ->disallowNewKeysInSubsequentConfigs()
106 ->useAttributeAsKey('key')
109 ->node('value', 'scalar')->end()
119 'a' => array('value' => 'foo'),
125 'b' => array('value' => 'foo'),
129 $tree->merge($a, $b);
132 public function testPerformsNoDeepMerging()
134 $tb = new TreeBuilder();
137 ->root('config', 'array')
139 ->node('no_deep_merging', 'array')
140 ->performNoDeepMerging()
142 ->node('foo', 'scalar')->end()
143 ->node('bar', 'scalar')->end()
152 'no_deep_merging' => array(
159 'no_deep_merging' => array(
164 $this->assertEquals(array(
165 'no_deep_merging' => array(
168 ), $tree->merge($a, $b));
171 public function testPrototypeWithoutAKeyAttribute()
173 $tb = new TreeBuilder();
176 ->root('config', 'array')
178 ->arrayNode('append_elements')
179 ->prototype('scalar')->end()
187 'append_elements' => array('a', 'b'),
191 'append_elements' => array('c', 'd'),
194 $this->assertEquals(array('append_elements' => array('a', 'b', 'c', 'd')), $tree->merge($a, $b));