Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
forks
theseer
Tokenizer
Commits
11336f6f
Commit
11336f6f
authored
5 years ago
by
Arne Blankerts
Browse files
Options
Download
Patches
Plain Diff
Ensure XMLSerializer can deal with empty token collections
parent
1c42705b
master
v1.2.0
v1.2.1
1.2.1
1.2.0
1.1.3
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/XMLSerializer.php
+8
-5
src/XMLSerializer.php
tests/XMLSerializerTest.php
+7
-0
tests/XMLSerializerTest.php
tests/_files/empty.xml
+2
-0
tests/_files/empty.xml
with
17 additions
and
5 deletions
+17
-5
src/XMLSerializer.php
+
8
−
5
View file @
11336f6f
...
...
@@ -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
();
...
...
This diff is collapsed.
Click to expand it.
tests/XMLSerializerTest.php
+
7
−
0
View file @
11336f6f
...
...
@@ -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
())));
}
}
This diff is collapsed.
Click to expand it.
tests/_files/empty.xml
0 → 100644
+
2
−
0
View file @
11336f6f
<?xml version="1.0"?>
<source
xmlns=
"https://github.com/theseer/tokenizer"
/>
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets