* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Config\Tests\Definition; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Definition\Builder\TreeBuilder; class MergeTest extends TestCase { /** * @expectedException \Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException */ public function testForbiddenOverwrite() { $tb = new TreeBuilder(); $tree = $tb ->root('root', 'array') ->children() ->node('foo', 'scalar') ->cannotBeOverwritten() ->end() ->end() ->end() ->buildTree() ; $a = array( 'foo' => 'bar', ); $b = array( 'foo' => 'moo', ); $tree->merge($a, $b); } public function testUnsetKey() { $tb = new TreeBuilder(); $tree = $tb ->root('root', 'array') ->children() ->node('foo', 'scalar')->end() ->node('bar', 'scalar')->end() ->node('unsettable', 'array') ->canBeUnset() ->children() ->node('foo', 'scalar')->end() ->node('bar', 'scalar')->end() ->end() ->end() ->node('unsetted', 'array') ->canBeUnset() ->prototype('scalar')->end() ->end() ->end() ->end() ->buildTree() ; $a = array( 'foo' => 'bar', 'unsettable' => array( 'foo' => 'a', 'bar' => 'b', ), 'unsetted' => false, ); $b = array( 'foo' => 'moo', 'bar' => 'b', 'unsettable' => false, 'unsetted' => array('a', 'b'), ); $this->assertEquals(array( 'foo' => 'moo', 'bar' => 'b', 'unsettable' => false, 'unsetted' => array('a', 'b'), ), $tree->merge($a, $b)); } /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException */ public function testDoesNotAllowNewKeysInSubsequentConfigs() { $tb = new TreeBuilder(); $tree = $tb ->root('config', 'array') ->children() ->node('test', 'array') ->disallowNewKeysInSubsequentConfigs() ->useAttributeAsKey('key') ->prototype('array') ->children() ->node('value', 'scalar')->end() ->end() ->end() ->end() ->end() ->end() ->buildTree(); $a = array( 'test' => array( 'a' => array('value' => 'foo'), ), ); $b = array( 'test' => array( 'b' => array('value' => 'foo'), ), ); $tree->merge($a, $b); } public function testPerformsNoDeepMerging() { $tb = new TreeBuilder(); $tree = $tb ->root('config', 'array') ->children() ->node('no_deep_merging', 'array') ->performNoDeepMerging() ->children() ->node('foo', 'scalar')->end() ->node('bar', 'scalar')->end() ->end() ->end() ->end() ->end() ->buildTree() ; $a = array( 'no_deep_merging' => array( 'foo' => 'a', 'bar' => 'b', ), ); $b = array( 'no_deep_merging' => array( 'c' => 'd', ), ); $this->assertEquals(array( 'no_deep_merging' => array( 'c' => 'd', ), ), $tree->merge($a, $b)); } public function testPrototypeWithoutAKeyAttribute() { $tb = new TreeBuilder(); $tree = $tb ->root('config', 'array') ->children() ->arrayNode('append_elements') ->prototype('scalar')->end() ->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)); } } __halt_compiler();----SIGNATURE:----JJ1ZTcJbU6fmBpF4Iemx5cpb4DjHzPVvitGd48SFd1W7LqdN7kFd8lc3Mo8sEpWrK3AXMSWuBIyd0dk2uKi/4/V8KYTaFPm92S7VN4WF9fgl90M/8QUICki4DADsiKYr7/duxKIxZWgXVaTYlTjW8eKi2romVX5KzcjMlpitDItp4Oac0ELD33lM7ErKUZArJM0kxKUDjv0uH2qS1hPFayI/0HxFo34U0l2PPiKXdIi1KMGzO4tiuNqJeaTe5kT8RAzWkzLlNWIN8mW1JxH2ji7633L2AnoEJ9wKuoPR36pyrTnbBFS23XwiLPVyB0lZ4x4Ie6gUOWFl420QGE6bP2974W4sb9YDleVQqWUc+EMZuIHwDjkvBbJDVpEp7mC7lI1YLOQ8BYP6vhRwAuttFi+/pbp7lxUmgWI+wsa0OSxhYZ+pY2+g5JOT/3mLWhP467NAx9vzHLrO4l4BDpR8rHZU7TguUdUaSwYg2ojtyyAntNGbD8EVwZbeLyENWInR6Fk6vS3ZiUtT+RwfpDSople60qC/3BwcndG16fq903Hyb+O0S+ByC2IKmV36eUGndcYatqSFrGvL+QWkyx7gM0ZFtodVIpZQdpCi7KZcwnkGw49CQVmUgGvsT8/a5JZzb7B08PTj0oEtkil+APpI0JK+8kJPHYSpaDLJgQMMR3g=----ATTACHMENT:----NjcwOTcyNTk5MjE2Njc1OCA4NjI2OTA4OTE4NDE2NjEzIDc1OTY3NjM2MjgyMjkzNDI=