XmlReferenceDumperTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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\XmlReferenceDumper;
  13. use Symfony\Component\Config\Tests\Fixtures\Configuration\ExampleConfiguration;
  14. class XmlReferenceDumperTest extends TestCase
  15. {
  16. public function testDumper()
  17. {
  18. $configuration = new ExampleConfiguration();
  19. $dumper = new XmlReferenceDumper();
  20. $this->assertEquals($this->getConfigurationAsString(), $dumper->dump($configuration));
  21. }
  22. public function testNamespaceDumper()
  23. {
  24. $configuration = new ExampleConfiguration();
  25. $dumper = new XmlReferenceDumper();
  26. $this->assertEquals(str_replace('http://example.org/schema/dic/acme_root', 'http://symfony.com/schema/dic/symfony', $this->getConfigurationAsString()), $dumper->dump($configuration, 'http://symfony.com/schema/dic/symfony'));
  27. }
  28. private function getConfigurationAsString()
  29. {
  30. return str_replace("\n", PHP_EOL, <<<'EOL'
  31. <!-- Namespace: http://example.org/schema/dic/acme_root -->
  32. <!-- scalar-required: Required -->
  33. <!-- enum-with-default: One of "this"; "that" -->
  34. <!-- enum: One of "this"; "that" -->
  35. <config
  36. boolean="true"
  37. scalar-empty=""
  38. scalar-null="null"
  39. scalar-true="true"
  40. scalar-false="false"
  41. scalar-default="default"
  42. scalar-array-empty=""
  43. scalar-array-defaults="elem1,elem2"
  44. scalar-required=""
  45. node-with-a-looong-name=""
  46. enum-with-default="this"
  47. enum=""
  48. >
  49. <!-- some info -->
  50. <!--
  51. child3: this is a long
  52. multi-line info text
  53. which should be indented;
  54. Example: example setting
  55. -->
  56. <array
  57. child1=""
  58. child2=""
  59. child3=""
  60. />
  61. <!-- prototype: Parameter name -->
  62. <parameter name="parameter name">scalar value</parameter>
  63. <!-- prototype -->
  64. <connection
  65. user=""
  66. pass=""
  67. />
  68. </config>
  69. EOL
  70. );
  71. }
  72. }