-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
NodeBuilderTest.php
94 lines (73 loc) · 2.67 KB
/
NodeBuilderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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\Builder;
use Symfony\Component\Config\Definition\Builder\NodeBuilder as BaseNodeBuilder;
use Symfony\Component\Config\Definition\Builder\VariableNodeDefinition as BaseVariableNodeDefinition;
class NodeBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \RuntimeException
*/
public function testThrowsAnExceptionWhenTryingToCreateANonRegisteredNodeType()
{
$builder = new BaseNodeBuilder();
$builder->node('', 'foobar');
}
/**
* @expectedException \RuntimeException
*/
public function testThrowsAnExceptionWhenTheNodeClassIsNotFound()
{
$builder = new BaseNodeBuilder();
$builder
->setNodeClass('noclasstype', '\\foo\\bar\\noclass')
->node('', 'noclasstype');
}
public function testAddingANewNodeType()
{
$class = __NAMESPACE__.'\\SomeNodeDefinition';
$builder = new BaseNodeBuilder();
$node = $builder
->setNodeClass('newtype', $class)
->node('', 'newtype');
$this->assertInstanceOf($class, $node);
}
public function testOverridingAnExistingNodeType()
{
$class = __NAMESPACE__.'\\SomeNodeDefinition';
$builder = new BaseNodeBuilder();
$node = $builder
->setNodeClass('variable', $class)
->node('', 'variable');
$this->assertInstanceOf($class, $node);
}
public function testNodeTypesAreNotCaseSensitive()
{
$builder = new BaseNodeBuilder();
$node1 = $builder->node('', 'VaRiAbLe');
$node2 = $builder->node('', 'variable');
$this->assertInstanceOf(get_class($node1), $node2);
$builder->setNodeClass('CuStOm', __NAMESPACE__.'\\SomeNodeDefinition');
$node1 = $builder->node('', 'CUSTOM');
$node2 = $builder->node('', 'custom');
$this->assertInstanceOf(get_class($node1), $node2);
}
public function testNumericNodeCreation()
{
$builder = new BaseNodeBuilder();
$node = $builder->integerNode('foo')->min(3)->max(5);
$this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition', $node);
$node = $builder->floatNode('bar')->min(3.0)->max(5.0);
$this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\FloatNodeDefinition', $node);
}
}
class SomeNodeDefinition extends BaseVariableNodeDefinition
{
}