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/Builder/TreeBuilderTest.php

93 lines
3.1 KiB
PHP
Raw Normal View History

[Config] Component refactoring The Config component API have changed and the extension configuration files must be updated accordingly: 1. Array nodes must enclosed their children definition in ->children() ... ->end() calls: Before: $treeBuilder->root('zend', 'array') ->arrayNode('logger') ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end(); After: $treeBuilder->root('zend', 'array') ->children() ->arrayNode('logger') ->children() ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end() ->end() ->end(); 2. The 'builder' method (in NodeBuilder) has been dropped in favor of an 'append' method (in ArrayNodeDefinition) Before: $treeBuilder->root('doctrine', 'array') ->arrayNode('dbal') ->builder($this->getDbalConnectionsNode()) ->end(); After: $treeBuilder->root('doctrine', 'array') ->children() ->arrayNode('dbal') ->append($this->getDbalConnectionsNode()) ->end() ->end(); 3. The root of a TreeBuilder is now an NodeDefinition (and most probably an ArrayNodeDefinition): Before: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(NodeBuilder $node) { ... } After: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(ArrayNodeDefinition $node) { ... } 4. The NodeBuilder API has changed (this is seldom used): Before: $node = new NodeBuilder('connections', 'array'); After: The recommended way is to use a tree builder: $treeBuilder = new TreeBuilder(); $node = $treeBuilder->root('connections', 'array'); An other way would be: $builder = new NodeBuilder(); $node = $builder->node('connections', 'array'); Some notes: - Tree root nodes should most always be array nodes, so this as been made the default: $treeBuilder->root('doctrine', 'array') is equivalent to $treeBuilder->root('doctrine') - There could be more than one ->children() ... ->end() sections. This could help with the readability: $treeBuilder->root('doctrine') ->children() ->scalarNode('default_connection')->end() ->end() ->fixXmlConfig('type') ->children() ->arrayNode('types') .... ->end() ->end()
2011-03-14 17:29:56 +00:00
<?php
2011-05-31 09:57:06 +01:00
/*
* 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.
*/
[Config] Component refactoring The Config component API have changed and the extension configuration files must be updated accordingly: 1. Array nodes must enclosed their children definition in ->children() ... ->end() calls: Before: $treeBuilder->root('zend', 'array') ->arrayNode('logger') ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end(); After: $treeBuilder->root('zend', 'array') ->children() ->arrayNode('logger') ->children() ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end() ->end() ->end(); 2. The 'builder' method (in NodeBuilder) has been dropped in favor of an 'append' method (in ArrayNodeDefinition) Before: $treeBuilder->root('doctrine', 'array') ->arrayNode('dbal') ->builder($this->getDbalConnectionsNode()) ->end(); After: $treeBuilder->root('doctrine', 'array') ->children() ->arrayNode('dbal') ->append($this->getDbalConnectionsNode()) ->end() ->end(); 3. The root of a TreeBuilder is now an NodeDefinition (and most probably an ArrayNodeDefinition): Before: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(NodeBuilder $node) { ... } After: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(ArrayNodeDefinition $node) { ... } 4. The NodeBuilder API has changed (this is seldom used): Before: $node = new NodeBuilder('connections', 'array'); After: The recommended way is to use a tree builder: $treeBuilder = new TreeBuilder(); $node = $treeBuilder->root('connections', 'array'); An other way would be: $builder = new NodeBuilder(); $node = $builder->node('connections', 'array'); Some notes: - Tree root nodes should most always be array nodes, so this as been made the default: $treeBuilder->root('doctrine', 'array') is equivalent to $treeBuilder->root('doctrine') - There could be more than one ->children() ... ->end() sections. This could help with the readability: $treeBuilder->root('doctrine') ->children() ->scalarNode('default_connection')->end() ->end() ->fixXmlConfig('type') ->children() ->arrayNode('types') .... ->end() ->end()
2011-03-14 17:29:56 +00:00
namespace Symfony\Tests\Component\Config\Definition\Builder;
use Symfony\Tests\Component\Config\Definition\Builder\NodeBuilder as CustomNodeBuilder;
[Config] Component refactoring The Config component API have changed and the extension configuration files must be updated accordingly: 1. Array nodes must enclosed their children definition in ->children() ... ->end() calls: Before: $treeBuilder->root('zend', 'array') ->arrayNode('logger') ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end(); After: $treeBuilder->root('zend', 'array') ->children() ->arrayNode('logger') ->children() ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end() ->end() ->end(); 2. The 'builder' method (in NodeBuilder) has been dropped in favor of an 'append' method (in ArrayNodeDefinition) Before: $treeBuilder->root('doctrine', 'array') ->arrayNode('dbal') ->builder($this->getDbalConnectionsNode()) ->end(); After: $treeBuilder->root('doctrine', 'array') ->children() ->arrayNode('dbal') ->append($this->getDbalConnectionsNode()) ->end() ->end(); 3. The root of a TreeBuilder is now an NodeDefinition (and most probably an ArrayNodeDefinition): Before: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(NodeBuilder $node) { ... } After: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(ArrayNodeDefinition $node) { ... } 4. The NodeBuilder API has changed (this is seldom used): Before: $node = new NodeBuilder('connections', 'array'); After: The recommended way is to use a tree builder: $treeBuilder = new TreeBuilder(); $node = $treeBuilder->root('connections', 'array'); An other way would be: $builder = new NodeBuilder(); $node = $builder->node('connections', 'array'); Some notes: - Tree root nodes should most always be array nodes, so this as been made the default: $treeBuilder->root('doctrine', 'array') is equivalent to $treeBuilder->root('doctrine') - There could be more than one ->children() ... ->end() sections. This could help with the readability: $treeBuilder->root('doctrine') ->children() ->scalarNode('default_connection')->end() ->end() ->fixXmlConfig('type') ->children() ->arrayNode('types') .... ->end() ->end()
2011-03-14 17:29:56 +00:00
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
[Config] Component refactoring The Config component API have changed and the extension configuration files must be updated accordingly: 1. Array nodes must enclosed their children definition in ->children() ... ->end() calls: Before: $treeBuilder->root('zend', 'array') ->arrayNode('logger') ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end(); After: $treeBuilder->root('zend', 'array') ->children() ->arrayNode('logger') ->children() ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end() ->end() ->end(); 2. The 'builder' method (in NodeBuilder) has been dropped in favor of an 'append' method (in ArrayNodeDefinition) Before: $treeBuilder->root('doctrine', 'array') ->arrayNode('dbal') ->builder($this->getDbalConnectionsNode()) ->end(); After: $treeBuilder->root('doctrine', 'array') ->children() ->arrayNode('dbal') ->append($this->getDbalConnectionsNode()) ->end() ->end(); 3. The root of a TreeBuilder is now an NodeDefinition (and most probably an ArrayNodeDefinition): Before: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(NodeBuilder $node) { ... } After: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(ArrayNodeDefinition $node) { ... } 4. The NodeBuilder API has changed (this is seldom used): Before: $node = new NodeBuilder('connections', 'array'); After: The recommended way is to use a tree builder: $treeBuilder = new TreeBuilder(); $node = $treeBuilder->root('connections', 'array'); An other way would be: $builder = new NodeBuilder(); $node = $builder->node('connections', 'array'); Some notes: - Tree root nodes should most always be array nodes, so this as been made the default: $treeBuilder->root('doctrine', 'array') is equivalent to $treeBuilder->root('doctrine') - There could be more than one ->children() ... ->end() sections. This could help with the readability: $treeBuilder->root('doctrine') ->children() ->scalarNode('default_connection')->end() ->end() ->fixXmlConfig('type') ->children() ->arrayNode('types') .... ->end() ->end()
2011-03-14 17:29:56 +00:00
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());
[Config] Component refactoring The Config component API have changed and the extension configuration files must be updated accordingly: 1. Array nodes must enclosed their children definition in ->children() ... ->end() calls: Before: $treeBuilder->root('zend', 'array') ->arrayNode('logger') ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end(); After: $treeBuilder->root('zend', 'array') ->children() ->arrayNode('logger') ->children() ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end() ->end() ->end(); 2. The 'builder' method (in NodeBuilder) has been dropped in favor of an 'append' method (in ArrayNodeDefinition) Before: $treeBuilder->root('doctrine', 'array') ->arrayNode('dbal') ->builder($this->getDbalConnectionsNode()) ->end(); After: $treeBuilder->root('doctrine', 'array') ->children() ->arrayNode('dbal') ->append($this->getDbalConnectionsNode()) ->end() ->end(); 3. The root of a TreeBuilder is now an NodeDefinition (and most probably an ArrayNodeDefinition): Before: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(NodeBuilder $node) { ... } After: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(ArrayNodeDefinition $node) { ... } 4. The NodeBuilder API has changed (this is seldom used): Before: $node = new NodeBuilder('connections', 'array'); After: The recommended way is to use a tree builder: $treeBuilder = new TreeBuilder(); $node = $treeBuilder->root('connections', 'array'); An other way would be: $builder = new NodeBuilder(); $node = $builder->node('connections', 'array'); Some notes: - Tree root nodes should most always be array nodes, so this as been made the default: $treeBuilder->root('doctrine', 'array') is equivalent to $treeBuilder->root('doctrine') - There could be more than one ->children() ... ->end() sections. This could help with the readability: $treeBuilder->root('doctrine') ->children() ->scalarNode('default_connection')->end() ->end() ->fixXmlConfig('type') ->children() ->arrayNode('types') .... ->end() ->end()
2011-03-14 17:29:56 +00:00
$nodeBuilder = $root->children();
$this->assertEquals(get_class($nodeBuilder), 'Symfony\Tests\Component\Config\Definition\Builder\NodeBuilder');
$nodeBuilder = $nodeBuilder->arrayNode('deeper')->children();
$this->assertEquals(get_class($nodeBuilder), 'Symfony\Tests\Component\Config\Definition\Builder\NodeBuilder');
}
public function testOverrideABuiltInNodeType()
{
$builder = new TreeBuilder();
$root = $builder->root('override', 'array', new CustomNodeBuilder());
[Config] Component refactoring The Config component API have changed and the extension configuration files must be updated accordingly: 1. Array nodes must enclosed their children definition in ->children() ... ->end() calls: Before: $treeBuilder->root('zend', 'array') ->arrayNode('logger') ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end(); After: $treeBuilder->root('zend', 'array') ->children() ->arrayNode('logger') ->children() ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end() ->end() ->end(); 2. The 'builder' method (in NodeBuilder) has been dropped in favor of an 'append' method (in ArrayNodeDefinition) Before: $treeBuilder->root('doctrine', 'array') ->arrayNode('dbal') ->builder($this->getDbalConnectionsNode()) ->end(); After: $treeBuilder->root('doctrine', 'array') ->children() ->arrayNode('dbal') ->append($this->getDbalConnectionsNode()) ->end() ->end(); 3. The root of a TreeBuilder is now an NodeDefinition (and most probably an ArrayNodeDefinition): Before: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(NodeBuilder $node) { ... } After: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(ArrayNodeDefinition $node) { ... } 4. The NodeBuilder API has changed (this is seldom used): Before: $node = new NodeBuilder('connections', 'array'); After: The recommended way is to use a tree builder: $treeBuilder = new TreeBuilder(); $node = $treeBuilder->root('connections', 'array'); An other way would be: $builder = new NodeBuilder(); $node = $builder->node('connections', 'array'); Some notes: - Tree root nodes should most always be array nodes, so this as been made the default: $treeBuilder->root('doctrine', 'array') is equivalent to $treeBuilder->root('doctrine') - There could be more than one ->children() ... ->end() sections. This could help with the readability: $treeBuilder->root('doctrine') ->children() ->scalarNode('default_connection')->end() ->end() ->fixXmlConfig('type') ->children() ->arrayNode('types') .... ->end() ->end()
2011-03-14 17:29:56 +00:00
$definition = $root->children()->variableNode('variable');
$this->assertEquals(get_class($definition), 'Symfony\Tests\Component\Config\Definition\Builder\VariableNodeDefinition');
}
public function testAddANodeType()
{
$builder = new TreeBuilder();
$root = $builder->root('override', 'array', new CustomNodeBuilder());
[Config] Component refactoring The Config component API have changed and the extension configuration files must be updated accordingly: 1. Array nodes must enclosed their children definition in ->children() ... ->end() calls: Before: $treeBuilder->root('zend', 'array') ->arrayNode('logger') ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end(); After: $treeBuilder->root('zend', 'array') ->children() ->arrayNode('logger') ->children() ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end() ->end() ->end(); 2. The 'builder' method (in NodeBuilder) has been dropped in favor of an 'append' method (in ArrayNodeDefinition) Before: $treeBuilder->root('doctrine', 'array') ->arrayNode('dbal') ->builder($this->getDbalConnectionsNode()) ->end(); After: $treeBuilder->root('doctrine', 'array') ->children() ->arrayNode('dbal') ->append($this->getDbalConnectionsNode()) ->end() ->end(); 3. The root of a TreeBuilder is now an NodeDefinition (and most probably an ArrayNodeDefinition): Before: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(NodeBuilder $node) { ... } After: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(ArrayNodeDefinition $node) { ... } 4. The NodeBuilder API has changed (this is seldom used): Before: $node = new NodeBuilder('connections', 'array'); After: The recommended way is to use a tree builder: $treeBuilder = new TreeBuilder(); $node = $treeBuilder->root('connections', 'array'); An other way would be: $builder = new NodeBuilder(); $node = $builder->node('connections', 'array'); Some notes: - Tree root nodes should most always be array nodes, so this as been made the default: $treeBuilder->root('doctrine', 'array') is equivalent to $treeBuilder->root('doctrine') - There could be more than one ->children() ... ->end() sections. This could help with the readability: $treeBuilder->root('doctrine') ->children() ->scalarNode('default_connection')->end() ->end() ->fixXmlConfig('type') ->children() ->arrayNode('types') .... ->end() ->end()
2011-03-14 17:29:56 +00:00
$definition = $root->children()->barNode('variable');
$this->assertEquals(get_class($definition), 'Symfony\Tests\Component\Config\Definition\Builder\BarNodeDefinition');
}
public function testCreateABuiltInNodeTypeWithACustomNodeBuilder()
{
$builder = new TreeBuilder();
$root = $builder->root('builtin', 'array', new CustomNodeBuilder());
[Config] Component refactoring The Config component API have changed and the extension configuration files must be updated accordingly: 1. Array nodes must enclosed their children definition in ->children() ... ->end() calls: Before: $treeBuilder->root('zend', 'array') ->arrayNode('logger') ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end(); After: $treeBuilder->root('zend', 'array') ->children() ->arrayNode('logger') ->children() ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end() ->end() ->end(); 2. The 'builder' method (in NodeBuilder) has been dropped in favor of an 'append' method (in ArrayNodeDefinition) Before: $treeBuilder->root('doctrine', 'array') ->arrayNode('dbal') ->builder($this->getDbalConnectionsNode()) ->end(); After: $treeBuilder->root('doctrine', 'array') ->children() ->arrayNode('dbal') ->append($this->getDbalConnectionsNode()) ->end() ->end(); 3. The root of a TreeBuilder is now an NodeDefinition (and most probably an ArrayNodeDefinition): Before: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(NodeBuilder $node) { ... } After: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(ArrayNodeDefinition $node) { ... } 4. The NodeBuilder API has changed (this is seldom used): Before: $node = new NodeBuilder('connections', 'array'); After: The recommended way is to use a tree builder: $treeBuilder = new TreeBuilder(); $node = $treeBuilder->root('connections', 'array'); An other way would be: $builder = new NodeBuilder(); $node = $builder->node('connections', 'array'); Some notes: - Tree root nodes should most always be array nodes, so this as been made the default: $treeBuilder->root('doctrine', 'array') is equivalent to $treeBuilder->root('doctrine') - There could be more than one ->children() ... ->end() sections. This could help with the readability: $treeBuilder->root('doctrine') ->children() ->scalarNode('default_connection')->end() ->end() ->fixXmlConfig('type') ->children() ->arrayNode('types') .... ->end() ->end()
2011-03-14 17:29:56 +00:00
$definition = $root->children()->booleanNode('boolean');
$this->assertEquals(get_class($definition), 'Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition');
}
public function testPrototypedArrayNodeUseTheCustomNodeBuilder()
{
$builder = new TreeBuilder();
$root = $builder->root('override', 'array', new CustomNodeBuilder());
[Config] Component refactoring The Config component API have changed and the extension configuration files must be updated accordingly: 1. Array nodes must enclosed their children definition in ->children() ... ->end() calls: Before: $treeBuilder->root('zend', 'array') ->arrayNode('logger') ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end(); After: $treeBuilder->root('zend', 'array') ->children() ->arrayNode('logger') ->children() ->scalarNode('priority')->defaultValue('INFO')->end() ->booleanNode('log_errors')->defaultFalse()->end() ->end() ->end() ->end(); 2. The 'builder' method (in NodeBuilder) has been dropped in favor of an 'append' method (in ArrayNodeDefinition) Before: $treeBuilder->root('doctrine', 'array') ->arrayNode('dbal') ->builder($this->getDbalConnectionsNode()) ->end(); After: $treeBuilder->root('doctrine', 'array') ->children() ->arrayNode('dbal') ->append($this->getDbalConnectionsNode()) ->end() ->end(); 3. The root of a TreeBuilder is now an NodeDefinition (and most probably an ArrayNodeDefinition): Before: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(NodeBuilder $node) { ... } After: $root = $treeBuilder->root('doctrine', 'array'); $this->addDbalSection($root); public function addDbalSection(ArrayNodeDefinition $node) { ... } 4. The NodeBuilder API has changed (this is seldom used): Before: $node = new NodeBuilder('connections', 'array'); After: The recommended way is to use a tree builder: $treeBuilder = new TreeBuilder(); $node = $treeBuilder->root('connections', 'array'); An other way would be: $builder = new NodeBuilder(); $node = $builder->node('connections', 'array'); Some notes: - Tree root nodes should most always be array nodes, so this as been made the default: $treeBuilder->root('doctrine', 'array') is equivalent to $treeBuilder->root('doctrine') - There could be more than one ->children() ... ->end() sections. This could help with the readability: $treeBuilder->root('doctrine') ->children() ->scalarNode('default_connection')->end() ->end() ->fixXmlConfig('type') ->children() ->arrayNode('types') .... ->end() ->end()
2011-03-14 17:29:56 +00:00
$root->prototype('bar')->end();
}
public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren()
{
$builder = new TreeBuilder();
$builder->root('propagation')
->children()
->setNodeClass('extended', 'Symfony\Tests\Component\Config\Definition\Builder\VariableNodeDefinition')
->node('foo', 'extended')->end()
->arrayNode('child')
->children()
->node('foo', 'extended')
->end()
->end()
->end()
->end();
}
2011-06-08 18:56:59 +01:00
}