FinalizationTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  13. use Symfony\Component\Config\Definition\NodeInterface;
  14. use Symfony\Component\Config\Definition\Processor;
  15. class FinalizationTest extends TestCase
  16. {
  17. public function testUnsetKeyWithDeepHierarchy()
  18. {
  19. $tb = new TreeBuilder();
  20. $tree = $tb
  21. ->root('config', 'array')
  22. ->children()
  23. ->node('level1', 'array')
  24. ->canBeUnset()
  25. ->children()
  26. ->node('level2', 'array')
  27. ->canBeUnset()
  28. ->children()
  29. ->node('somevalue', 'scalar')->end()
  30. ->node('anothervalue', 'scalar')->end()
  31. ->end()
  32. ->end()
  33. ->node('level1_scalar', 'scalar')->end()
  34. ->end()
  35. ->end()
  36. ->end()
  37. ->end()
  38. ->buildTree()
  39. ;
  40. $a = array(
  41. 'level1' => array(
  42. 'level2' => array(
  43. 'somevalue' => 'foo',
  44. 'anothervalue' => 'bar',
  45. ),
  46. 'level1_scalar' => 'foo',
  47. ),
  48. );
  49. $b = array(
  50. 'level1' => array(
  51. 'level2' => false,
  52. ),
  53. );
  54. $this->assertEquals(array(
  55. 'level1' => array(
  56. 'level1_scalar' => 'foo',
  57. ),
  58. ), $this->process($tree, array($a, $b)));
  59. }
  60. protected function process(NodeInterface $tree, array $configs)
  61. {
  62. $processor = new Processor();
  63. return $processor->process($tree, $configs);
  64. }
  65. }