XmlReaderCasterTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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\VarDumper\Tests\Caster;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
  13. /**
  14. * @author Baptiste Clavié <clavie.b@gmail.com>
  15. */
  16. class XmlReaderCasterTest extends TestCase
  17. {
  18. use VarDumperTestTrait;
  19. /** @var \XmlReader */
  20. private $reader;
  21. protected function setUp()
  22. {
  23. $this->reader = new \XmlReader();
  24. $this->reader->open(__DIR__.'/../Fixtures/xml_reader.xml');
  25. }
  26. protected function tearDown()
  27. {
  28. $this->reader->close();
  29. }
  30. public function testParserProperty()
  31. {
  32. $this->reader->setParserProperty(\XMLReader::SUBST_ENTITIES, true);
  33. $expectedDump = <<<'EODUMP'
  34. XMLReader {
  35. +nodeType: NONE
  36. parserProperties: {
  37. SUBST_ENTITIES: true
  38. …3
  39. }
  40. …12
  41. }
  42. EODUMP;
  43. $this->assertDumpMatchesFormat($expectedDump, $this->reader);
  44. }
  45. /**
  46. * @dataProvider provideNodes
  47. */
  48. public function testNodes($seek, $expectedDump)
  49. {
  50. while ($seek--) {
  51. $this->reader->read();
  52. }
  53. $this->assertDumpMatchesFormat($expectedDump, $this->reader);
  54. }
  55. public function provideNodes()
  56. {
  57. return array(
  58. array(0, <<<'EODUMP'
  59. XMLReader {
  60. +nodeType: NONE
  61. …13
  62. }
  63. EODUMP
  64. ),
  65. array(1, <<<'EODUMP'
  66. XMLReader {
  67. +localName: "foo"
  68. +nodeType: ELEMENT
  69. +baseURI: "%sxml_reader.xml"
  70. …11
  71. }
  72. EODUMP
  73. ),
  74. array(2, <<<'EODUMP'
  75. XMLReader {
  76. +localName: "#text"
  77. +nodeType: SIGNIFICANT_WHITESPACE
  78. +depth: 1
  79. +value: """
  80. \n
  81. """
  82. +baseURI: "%sxml_reader.xml"
  83. …9
  84. }
  85. EODUMP
  86. ),
  87. array(3, <<<'EODUMP'
  88. XMLReader {
  89. +localName: "bar"
  90. +nodeType: ELEMENT
  91. +depth: 1
  92. +baseURI: "%sxml_reader.xml"
  93. …10
  94. }
  95. EODUMP
  96. ),
  97. array(4, <<<'EODUMP'
  98. XMLReader {
  99. +localName: "bar"
  100. +nodeType: END_ELEMENT
  101. +depth: 1
  102. +baseURI: "%sxml_reader.xml"
  103. …10
  104. }
  105. EODUMP
  106. ),
  107. array(6, <<<'EODUMP'
  108. XMLReader {
  109. +localName: "bar"
  110. +nodeType: ELEMENT
  111. +depth: 1
  112. +isEmptyElement: true
  113. +baseURI: "%sxml_reader.xml"
  114. …9
  115. }
  116. EODUMP
  117. ),
  118. array(9, <<<'EODUMP'
  119. XMLReader {
  120. +localName: "#text"
  121. +nodeType: TEXT
  122. +depth: 2
  123. +value: "With text"
  124. +baseURI: "%sxml_reader.xml"
  125. …9
  126. }
  127. EODUMP
  128. ),
  129. array(12, <<<'EODUMP'
  130. XMLReader {
  131. +localName: "bar"
  132. +nodeType: ELEMENT
  133. +depth: 1
  134. +attributeCount: 2
  135. +baseURI: "%sxml_reader.xml"
  136. …9
  137. }
  138. EODUMP
  139. ),
  140. array(13, <<<'EODUMP'
  141. XMLReader {
  142. +localName: "bar"
  143. +nodeType: END_ELEMENT
  144. +depth: 1
  145. +baseURI: "%sxml_reader.xml"
  146. …10
  147. }
  148. EODUMP
  149. ),
  150. array(15, <<<'EODUMP'
  151. XMLReader {
  152. +localName: "bar"
  153. +nodeType: ELEMENT
  154. +depth: 1
  155. +attributeCount: 1
  156. +baseURI: "%sxml_reader.xml"
  157. …9
  158. }
  159. EODUMP
  160. ),
  161. array(16, <<<'EODUMP'
  162. XMLReader {
  163. +localName: "#text"
  164. +nodeType: SIGNIFICANT_WHITESPACE
  165. +depth: 2
  166. +value: """
  167. \n
  168. """
  169. +baseURI: "%sxml_reader.xml"
  170. …9
  171. }
  172. EODUMP
  173. ),
  174. array(17, <<<'EODUMP'
  175. XMLReader {
  176. +localName: "baz"
  177. +prefix: "baz"
  178. +nodeType: ELEMENT
  179. +depth: 2
  180. +namespaceURI: "http://symfony.com"
  181. +baseURI: "%sxml_reader.xml"
  182. …8
  183. }
  184. EODUMP
  185. ),
  186. array(18, <<<'EODUMP'
  187. XMLReader {
  188. +localName: "baz"
  189. +prefix: "baz"
  190. +nodeType: END_ELEMENT
  191. +depth: 2
  192. +namespaceURI: "http://symfony.com"
  193. +baseURI: "%sxml_reader.xml"
  194. …8
  195. }
  196. EODUMP
  197. ),
  198. array(19, <<<'EODUMP'
  199. XMLReader {
  200. +localName: "#text"
  201. +nodeType: SIGNIFICANT_WHITESPACE
  202. +depth: 2
  203. +value: """
  204. \n
  205. """
  206. +baseURI: "%sxml_reader.xml"
  207. …9
  208. }
  209. EODUMP
  210. ),
  211. array(21, <<<'EODUMP'
  212. XMLReader {
  213. +localName: "#text"
  214. +nodeType: SIGNIFICANT_WHITESPACE
  215. +depth: 1
  216. +value: "\n"
  217. +baseURI: "%sxml_reader.xml"
  218. …9
  219. }
  220. EODUMP
  221. ),
  222. array(22, <<<'EODUMP'
  223. XMLReader {
  224. +localName: "foo"
  225. +nodeType: END_ELEMENT
  226. +baseURI: "%sxml_reader.xml"
  227. …11
  228. }
  229. EODUMP
  230. ),
  231. );
  232. }
  233. }