Skip to content

Commit 41a9f80

Browse files
committed
IHF: array_to_xml helper tests added.
1 parent d185cfc commit 41a9f80

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

tests/xml/ArrayToXmlTest.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function it_converts_array_to_xml()
3131
}
3232

3333
/** @test */
34-
public function is_supports_xml_attributes_in_converting()
34+
public function it_supports_xml_attributes_in_converting()
3535
{
3636
$array = [
3737
'task' => [
@@ -68,7 +68,7 @@ public function is_supports_xml_attributes_in_converting()
6868
}
6969

7070
/** @test */
71-
public function is_supports_custom_root_element_name()
71+
public function it_supports_custom_root_element_name()
7272
{
7373
$array = [
7474
'task' => [
@@ -94,4 +94,32 @@ public function is_supports_custom_root_element_name()
9494

9595
$this->assertEquals($expected, array_to_xml($array, 'tasks'));
9696
}
97+
98+
/** @test */
99+
public function it_replaces_spaces_by_under_scores_in_key_names_by_default()
100+
{
101+
$array = [
102+
'task' => [
103+
0 => [
104+
'to who' => 'John',
105+
'from who' => 'Jane',
106+
'title' => 'Go to the shop',
107+
],
108+
1 => [
109+
'to who' => 'John',
110+
'from who' => 'Paul',
111+
'title' => 'Finish the report',
112+
],
113+
2 => [
114+
'to who' => 'Jane',
115+
'from who' => 'Jeff',
116+
'title' => 'Clean the house',
117+
],
118+
],
119+
];
120+
121+
$expected = file_get_contents(__DIR__ . '/ArrayToXmlTest/with-spaces.xml');
122+
123+
$this->assertEquals($expected, array_to_xml($array));
124+
}
97125
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0"?>
2+
<root><task><to_who>John</to_who><from_who>Jane</from_who><title>Go to the shop</title></task><task><to_who>John</to_who><from_who>Paul</from_who><title>Finish the report</title></task><task><to_who>Jane</to_who><from_who>Jeff</from_who><title>Clean the house</title></task></root>

0 commit comments

Comments
 (0)