YamlReferenceDumperTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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\Dumper;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Definition\Dumper\YamlReferenceDumper;
  13. use Symfony\Component\Config\Tests\Fixtures\Configuration\ExampleConfiguration;
  14. class YamlReferenceDumperTest extends TestCase
  15. {
  16. public function testDumper()
  17. {
  18. $configuration = new ExampleConfiguration();
  19. $dumper = new YamlReferenceDumper();
  20. $this->assertEquals($this->getConfigurationAsString(), $dumper->dump($configuration));
  21. }
  22. public function provideDumpAtPath()
  23. {
  24. return [
  25. 'Regular node' => ['scalar_true', <<<EOL
  26. scalar_true: true
  27. EOL
  28. ],
  29. 'Array node' => ['array', <<<EOL
  30. # some info
  31. array:
  32. child1: ~
  33. child2: ~
  34. # this is a long
  35. # multi-line info text
  36. # which should be indented
  37. child3: ~ # Example: example setting
  38. EOL
  39. ],
  40. 'Regular nested' => ['array.child2', <<<EOL
  41. child2: ~
  42. EOL
  43. ],
  44. 'Prototype' => ['cms_pages.page', <<<EOL
  45. # Prototype
  46. page:
  47. # Prototype
  48. locale:
  49. title: ~ # Required
  50. path: ~ # Required
  51. EOL
  52. ],
  53. 'Nested prototype' => ['cms_pages.page.locale', <<<EOL
  54. # Prototype
  55. locale:
  56. title: ~ # Required
  57. path: ~ # Required
  58. EOL
  59. ],
  60. ];
  61. }
  62. /**
  63. * @dataProvider provideDumpAtPath
  64. */
  65. public function testDumpAtPath($path, $expected)
  66. {
  67. $configuration = new ExampleConfiguration();
  68. $dumper = new YamlReferenceDumper();
  69. $this->assertSame(trim($expected), trim($dumper->dumpAtPath($configuration, $path)));
  70. }
  71. private function getConfigurationAsString()
  72. {
  73. return <<<'EOL'
  74. acme_root:
  75. boolean: true
  76. scalar_empty: ~
  77. scalar_null: null
  78. scalar_true: true
  79. scalar_false: false
  80. scalar_default: default
  81. scalar_array_empty: []
  82. scalar_array_defaults:
  83. # Defaults:
  84. - elem1
  85. - elem2
  86. scalar_required: ~ # Required
  87. scalar_deprecated: ~ # Deprecated (The child node "scalar_deprecated" at path "acme_root" is deprecated.)
  88. scalar_deprecated_with_message: ~ # Deprecated (Deprecation custom message for "scalar_deprecated_with_message" at "acme_root")
  89. node_with_a_looong_name: ~
  90. enum_with_default: this # One of "this"; "that"
  91. enum: ~ # One of "this"; "that"
  92. # some info
  93. array:
  94. child1: ~
  95. child2: ~
  96. # this is a long
  97. # multi-line info text
  98. # which should be indented
  99. child3: ~ # Example: example setting
  100. scalar_prototyped: []
  101. parameters:
  102. # Prototype: Parameter name
  103. name: ~
  104. connections:
  105. # Prototype
  106. -
  107. user: ~
  108. pass: ~
  109. cms_pages:
  110. # Prototype
  111. page:
  112. # Prototype
  113. locale:
  114. title: ~ # Required
  115. path: ~ # Required
  116. pipou:
  117. # Prototype
  118. name: []
  119. EOL;
  120. }
  121. }