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\Builder;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\Definition\Builder\NodeBuilder as BaseNodeBuilder;
16 use Symfony\Component\Config\Definition\Builder\VariableNodeDefinition as BaseVariableNodeDefinition;
18 class NodeBuilderTest extends TestCase
21 * @expectedException \RuntimeException
23 public function testThrowsAnExceptionWhenTryingToCreateANonRegisteredNodeType()
25 $builder = new BaseNodeBuilder();
26 $builder->node('', 'foobar');
30 * @expectedException \RuntimeException
32 public function testThrowsAnExceptionWhenTheNodeClassIsNotFound()
34 $builder = new BaseNodeBuilder();
36 ->setNodeClass('noclasstype', '\\foo\\bar\\noclass')
37 ->node('', 'noclasstype');
40 public function testAddingANewNodeType()
42 $class = __NAMESPACE__.'\\SomeNodeDefinition';
44 $builder = new BaseNodeBuilder();
46 ->setNodeClass('newtype', $class)
47 ->node('', 'newtype');
49 $this->assertInstanceOf($class, $node);
52 public function testOverridingAnExistingNodeType()
54 $class = __NAMESPACE__.'\\SomeNodeDefinition';
56 $builder = new BaseNodeBuilder();
58 ->setNodeClass('variable', $class)
59 ->node('', 'variable');
61 $this->assertInstanceOf($class, $node);
64 public function testNodeTypesAreNotCaseSensitive()
66 $builder = new BaseNodeBuilder();
68 $node1 = $builder->node('', 'VaRiAbLe');
69 $node2 = $builder->node('', 'variable');
71 $this->assertInstanceOf(\get_class($node1), $node2);
73 $builder->setNodeClass('CuStOm', __NAMESPACE__.'\\SomeNodeDefinition');
75 $node1 = $builder->node('', 'CUSTOM');
76 $node2 = $builder->node('', 'custom');
78 $this->assertInstanceOf(\get_class($node1), $node2);
81 public function testNumericNodeCreation()
83 $builder = new BaseNodeBuilder();
85 $node = $builder->integerNode('foo')->min(3)->max(5);
86 $this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition', $node);
88 $node = $builder->floatNode('bar')->min(3.0)->max(5.0);
89 $this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\FloatNodeDefinition', $node);
93 class SomeNodeDefinition extends BaseVariableNodeDefinition