Commit 11336f6f authored by Arne Blankerts's avatar Arne Blankerts
Browse files

Ensure XMLSerializer can deal with empty token collections

No related merge requests found
Showing with 17 additions and 5 deletions
+17 -5
......@@ -57,12 +57,15 @@ class XMLSerializer {
$this->writer->startDocument();
$this->writer->startElement('source');
$this->writer->writeAttribute('xmlns', $this->xmlns->asString());
$this->writer->startElement('line');
$this->writer->writeAttribute('no', '1');
$this->previousToken = $tokens[0];
foreach ($tokens as $token) {
$this->addToken($token);
if (count($tokens) > 0) {
$this->writer->startElement('line');
$this->writer->writeAttribute('no', '1');
$this->previousToken = $tokens[0];
foreach ($tokens as $token) {
$this->addToken($token);
}
}
$this->writer->endElement();
......
......@@ -40,4 +40,11 @@ class XMLSerializerTest extends TestCase {
$this->assertEquals($expected, $serializer->toXML($this->tokens));
}
public function testEmptyCollectionCreatesEmptyDocument() {
$expected = file_get_contents(__DIR__ . '/_files/empty.xml');
$serializer = new XMLSerializer();
$this->assertEquals($expected, $serializer->toXML((new TokenCollection())));
}
}
<?xml version="1.0"?>
<source xmlns="https://github.com/theseer/tokenizer"/>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment