Skip to content

Commit 160f165

Browse files
committed
IHF: xml_to_array tests added.
1 parent 602470b commit 160f165

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

tests/xml/XmlToArrayTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
class XmlToArrayTest extends TestCase
4+
{
5+
/** @test */
6+
public function it_transforms_xml_string_to_array()
7+
{
8+
$xml = file_get_contents(__DIR__ . '/XmlToArrayTest/example.xml');
9+
10+
$expected = [
11+
'tasks' => [
12+
'task' => [
13+
0 => [
14+
'to' => 'John',
15+
'from' => 'Jane',
16+
'title' => 'Go to the shop',
17+
],
18+
1 => [
19+
'to' => 'John',
20+
'from' => 'Paul',
21+
'title' => 'Finish the report',
22+
],
23+
2 => [
24+
'to' => 'Jane',
25+
'from' => 'Jeff',
26+
'title' => 'Clean the house',
27+
],
28+
],
29+
],
30+
];
31+
32+
$this->assertEquals($expected, xml_to_array($xml));
33+
}
34+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<root>
3+
<tasks>
4+
<task>
5+
<to>John</to>
6+
<from>Jane</from>
7+
<title>Go to the shop</title>
8+
</task>
9+
<task>
10+
<to>John</to>
11+
<from>Paul</from>
12+
<title>Finish the report</title>
13+
</task>
14+
<task>
15+
<to>Jane</to>
16+
<from>Jeff</from>
17+
<title>Clean the house</title>
18+
</task>
19+
</tasks>
20+
</root>

0 commit comments

Comments
 (0)