FinalizationTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Config\Tests\Definition;
  11. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  12. use Symfony\Component\Config\Definition\Processor;
  13. use Symfony\Component\Config\Definition\NodeInterface;
  14. class FinalizationTest extends \PHPUnit_Framework_TestCase
  15. {
  16. public function testUnsetKeyWithDeepHierarchy()
  17. {
  18. $tb = new TreeBuilder();
  19. $tree = $tb
  20. ->root('config', 'array')
  21. ->children()
  22. ->node('level1', 'array')
  23. ->canBeUnset()
  24. ->children()
  25. ->node('level2', 'array')
  26. ->canBeUnset()
  27. ->children()
  28. ->node('somevalue', 'scalar')->end()
  29. ->node('anothervalue', 'scalar')->end()
  30. ->end()
  31. ->end()
  32. ->node('level1_scalar', 'scalar')->end()
  33. ->end()
  34. ->end()
  35. ->end()
  36. ->end()
  37. ->buildTree()
  38. ;
  39. $a = array(
  40. 'level1' => array(
  41. 'level2' => array(
  42. 'somevalue' => 'foo',
  43. 'anothervalue' => 'bar',
  44. ),
  45. 'level1_scalar' => 'foo',
  46. ),
  47. );
  48. $b = array(
  49. 'level1' => array(
  50. 'level2' => false,
  51. ),
  52. );
  53. $this->assertEquals(array(
  54. 'level1' => array(
  55. 'level1_scalar' => 'foo',
  56. ),
  57. ), $this->process($tree, array($a, $b)));
  58. }
  59. protected function process(NodeInterface $tree, array $configs)
  60. {
  61. $processor = new Processor();
  62. return $processor->process($tree, $configs);
  63. }
  64. }