Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Config] Ability to add and override node types without having to sub…
…class NodeBuilder
- Loading branch information
Showing
3 changed files
with
144 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
tests/Symfony/Tests/Component/Config/Definition/Builder/NodeBuilderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Symfony\Tests\Component\Config\Definition\Builder; | ||
|
||
use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||
use Symfony\Component\Config\Definition\Builder\VariableNodeDefinition; | ||
|
||
class NodeBuilderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @expectedException \RuntimeException | ||
*/ | ||
public function testThrowsAnExceptionWhenTryingToCreateANonRegisteredNodeType() | ||
{ | ||
$builder = new NodeBuilder(); | ||
$builder->node('', 'foobar'); | ||
} | ||
|
||
/** | ||
* @expectedException \RuntimeException | ||
*/ | ||
public function testThrowsAnExceptionWhenTheNodeClassIsNotFound() | ||
{ | ||
$builder = new NodeBuilder(); | ||
$builder | ||
->setNodeClass('noclasstype', '\\foo\\bar\\noclass') | ||
->node('', 'noclasstype'); | ||
} | ||
|
||
public function testAddingANewNodeType() | ||
{ | ||
$class = __NAMESPACE__.'\\SomeNodeDefinition'; | ||
|
||
$builder = new NodeBuilder(); | ||
$node = $builder | ||
->setNodeClass('newtype', $class) | ||
->node('', 'newtype'); | ||
|
||
$this->assertEquals(get_class($node), $class); | ||
} | ||
|
||
public function testOverridingAnExistingNodeType() | ||
{ | ||
$class = __NAMESPACE__.'\\SomeNodeDefinition'; | ||
|
||
$builder = new NodeBuilder(); | ||
$node = $builder | ||
->setNodeClass('variable', $class) | ||
->node('', 'variable'); | ||
|
||
$this->assertEquals(get_class($node), $class); | ||
} | ||
|
||
public function testNodeTypesAreNotCaseSensitive() | ||
{ | ||
$builder = new NodeBuilder(); | ||
|
||
$node1 = $builder->node('', 'VaRiAbLe'); | ||
$node2 = $builder->node('', 'variable'); | ||
|
||
$this->assertEquals(get_class($node1), get_class($node2)); | ||
|
||
$builder->setNodeClass('CuStOm', __NAMESPACE__.'\\SomeNodeDefinition'); | ||
|
||
$node1 = $builder->node('', 'CUSTOM'); | ||
$node2 = $builder->node('', 'custom'); | ||
|
||
$this->assertEquals(get_class($node1), get_class($node2)); | ||
} | ||
} | ||
|
||
class SomeNodeDefinition extends VariableNodeDefinition | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters