Advertisement
Guest User

Untitled

a guest
May 5th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <?php
  2.  
  3. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  4. use Symfony\Component\Config\Definition\ConfigurationInterface;
  5. use Symfony\Component\Config\Definition\Processor;
  6.  
  7. class ConfigurationTest extends \PHPUnit_Framework_TestCase
  8. {
  9. public function testProcessConfiguration()
  10. {
  11. $configs = [
  12. [
  13. 'array1' => [
  14. 'key1' => [
  15. 'array2' => []
  16. ],
  17. 'key2' => [
  18. 'array3' => []
  19. ]
  20. ]
  21. ]
  22. ];
  23.  
  24. $processor = new Processor();
  25. $config = $processor->processConfiguration(new Configuration(), $configs);
  26.  
  27. $this->assertArrayHasKey('array1', $config);
  28. $this->assertEquals($configs[0]['array1'], $config['array1']);
  29. }
  30. }
  31.  
  32. class Configuration implements ConfigurationInterface
  33. {
  34. public function getConfigTreeBuilder()
  35. {
  36. $treeBuilder = new TreeBuilder();
  37.  
  38. $rootNode = $treeBuilder->root('root');
  39. $rootNode
  40. ->children()
  41. ->arrayNode('array1')
  42. ->useAttributeAsKey('name')
  43. ->prototype('array')
  44. ->children()
  45. ->arrayNode('array2')
  46. ->prototype('variable')->end()
  47. // ->children()->end()
  48. ->end()
  49. ->arrayNode('array3')
  50. ->prototype('variable')->end()
  51. // ->children()->end()
  52. ->end()
  53. ->end()
  54. ->end()
  55. ;
  56.  
  57. return $treeBuilder;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement