This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Component/Config/Definition/MergeTest.php
Fabien Potencier 17cd08dc6c fixed CS
2011-06-08 19:56:59 +02:00

196 lines
5.0 KiB
PHP

<?php
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Symfony\Tests\Component\Config\Definition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
class MergeTest extends \PHPUnit_Framework_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));
}
}