Skip to content

Commit 321e748

Browse files
committed
IHF: array_to_xml and xml_to_array compatibility tests added.
1 parent 1b5d4a1 commit 321e748

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

tests/xml/ArrayToXmlTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,39 @@ public function it_replaces_spaces_by_under_scores_in_key_names_by_default()
122122

123123
$this->assertEquals($expected, array_to_xml($array));
124124
}
125+
126+
/** @test */
127+
public function it_is_fully_compatible_with_xml_to_array_helper()
128+
{
129+
$array = [
130+
'task' => [
131+
0 => [
132+
'to' => 'John',
133+
'from' => 'Jane',
134+
'title' => 'Go to the shop',
135+
'@attributes' => [
136+
'priority' => 'low',
137+
],
138+
],
139+
1 => [
140+
'to' => 'John',
141+
'from' => 'Paul',
142+
'title' => 'Finish the report',
143+
'@attributes' => [
144+
'priority' => 'medium',
145+
],
146+
],
147+
2 => [
148+
'to' => 'Jane',
149+
'from' => 'Jeff',
150+
'title' => 'Clean the house',
151+
'@attributes' => [
152+
'priority' => 'high',
153+
],
154+
],
155+
],
156+
];
157+
158+
$this->assertEquals($array, xml_to_array(array_to_xml($array)));
159+
}
125160
}

tests/xml/XmlToArrayTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,12 @@ public function it_throws_an_exception_if_non_xml_string_passed()
8787

8888
xml_to_array('Non XML');
8989
}
90+
91+
/** @test */
92+
public function it_is_fully_compatible_with_array_to_xml_helper()
93+
{
94+
$xml = file_get_contents(__DIR__ . '/XmlToArrayTest/example.xml');
95+
96+
$this->assertEquals($xml, array_to_xml(xml_to_array($xml)));
97+
}
9098
}

tests/xml/XmlToArrayTest/example.xml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,2 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<root>
3-
<tasks>
4-
<task priority="low">
5-
<to>John</to>
6-
<from>Jane</from>
7-
<title>Go to the shop</title>
8-
</task>
9-
<task priority="medium">
10-
<to>John</to>
11-
<from>Paul</from>
12-
<title>Finish the report</title>
13-
</task>
14-
<task priority="high">
15-
<to>Jane</to>
16-
<from>Jeff</from>
17-
<title>Clean the house</title>
18-
</task>
19-
</tasks>
20-
</root>
1+
<?xml version="1.0"?>
2+
<root><tasks><task priority="low"><to>John</to><from>Jane</from><title>Go to the shop</title></task><task priority="medium"><to>John</to><from>Paul</from><title>Finish the report</title></task><task priority="high"><to>Jane</to><from>Jeff</from><title>Clean the house</title></task></tasks></root>

0 commit comments

Comments
 (0)