<?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\Builder;
use Symfony\Tests\Component\Config\Definition\Builder\NodeBuilder as CustomNodeBuilder;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
require __DIR__.'/../../Fixtures/Builder/NodeBuilder.php';
require __DIR__.'/../../Fixtures/Builder/BarNodeDefinition.php';
require __DIR__.'/../../Fixtures/Builder/VariableNodeDefinition.php';
class TreeBuilderTest extends \PHPUnit_Framework_TestCase
{
public function testUsingACustomNodeBuilder()
$builder = new TreeBuilder();
$root = $builder->root('custom', 'array', new CustomNodeBuilder());
$nodeBuilder = $root->children();
$this->assertEquals(get_class($nodeBuilder), 'Symfony\Tests\Component\Config\Definition\Builder\NodeBuilder');
$nodeBuilder = $nodeBuilder->arrayNode('deeper')->children();
}
public function testOverrideABuiltInNodeType()
$root = $builder->root('override', 'array', new CustomNodeBuilder());
$definition = $root->children()->variableNode('variable');
$this->assertEquals(get_class($definition), 'Symfony\Tests\Component\Config\Definition\Builder\VariableNodeDefinition');
public function testAddANodeType()
$definition = $root->children()->barNode('variable');
$this->assertEquals(get_class($definition), 'Symfony\Tests\Component\Config\Definition\Builder\BarNodeDefinition');
public function testCreateABuiltInNodeTypeWithACustomNodeBuilder()
$root = $builder->root('builtin', 'array', new CustomNodeBuilder());
$definition = $root->children()->booleanNode('boolean');
$this->assertEquals(get_class($definition), 'Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition');
public function testPrototypedArrayNodeUseTheCustomNodeBuilder()
$root->prototype('bar')->end();
public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren()
$builder->root('propagation')
->children()
->setNodeClass('extended', 'Symfony\Tests\Component\Config\Definition\Builder\VariableNodeDefinition')
->node('foo', 'extended')->end()
->arrayNode('child')
->node('foo', 'extended')
->end()
->end();