ArrayNodeDefinitionTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Tests\Component\Config\Definition\Builder;
  11. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  12. use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
  13. class ArrayNodeDefinitionTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testAppendingSomeNode()
  16. {
  17. $parent = new ArrayNodeDefinition('root');
  18. $child = new ScalarNodeDefinition('child');
  19. $node = $parent
  20. ->children()
  21. ->scalarNode('foo')->end()
  22. ->scalarNode('bar')->end()
  23. ->end()
  24. ->append($child);
  25. $this->assertEquals(count($this->getField($parent, 'children')), 3);
  26. $this->assertTrue(in_array($child, $this->getField($parent, 'children')));
  27. }
  28. protected function getField($object, $field)
  29. {
  30. $reflection = new \ReflectionProperty($object, $field);
  31. $reflection->setAccessible(true);
  32. return $reflection->getValue($object);
  33. }
  34. }