XMLSerializerTest.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php declare(strict_types = 1);
  2. namespace TheSeer\Tokenizer;
  3. use PHPUnit\Framework\TestCase;
  4. /**
  5. * @covers \TheSeer\Tokenizer\XMLSerializer
  6. */
  7. class XMLSerializerTest extends TestCase {
  8. /** @var TokenCollection $tokens */
  9. private $tokens;
  10. protected function setUp() {
  11. $this->tokens = unserialize(
  12. file_get_contents(__DIR__ . '/_files/test.php.tokens'),
  13. [TokenCollection::class]
  14. );
  15. }
  16. public function testCanBeSerializedToXml() {
  17. $expected = file_get_contents(__DIR__ . '/_files/test.php.xml');
  18. $serializer = new XMLSerializer();
  19. $this->assertEquals($expected, $serializer->toXML($this->tokens));
  20. }
  21. public function testCanBeSerializedToDomDocument() {
  22. $serializer = new XMLSerializer();
  23. $result = $serializer->toDom($this->tokens);
  24. $this->assertInstanceOf(\DOMDocument::class, $result);
  25. $this->assertEquals('source', $result->documentElement->localName);
  26. }
  27. public function testCanBeSerializedToXmlWithCustomNamespace() {
  28. $expected = file_get_contents(__DIR__ . '/_files/customns.xml');
  29. $serializer = new XMLSerializer(new NamespaceUri('custom:xml:namespace'));
  30. $this->assertEquals($expected, $serializer->toXML($this->tokens));
  31. }
  32. }