File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -31,4 +31,34 @@ public function it_transforms_xml_string_to_array()
3131
3232 $ this ->assertEquals ($ expected , xml_to_array ($ xml ));
3333 }
34+
35+ /** @test */
36+ public function it_also_allows_to_pass_simplexmlelement_object ()
37+ {
38+ $ xml = new SimpleXMLElement (file_get_contents (__DIR__ . '/XmlToArrayTest/example.xml ' ));
39+
40+ $ expected = [
41+ 'tasks ' => [
42+ 'task ' => [
43+ 0 => [
44+ 'to ' => 'John ' ,
45+ 'from ' => 'Jane ' ,
46+ 'title ' => 'Go to the shop ' ,
47+ ],
48+ 1 => [
49+ 'to ' => 'John ' ,
50+ 'from ' => 'Paul ' ,
51+ 'title ' => 'Finish the report ' ,
52+ ],
53+ 2 => [
54+ 'to ' => 'Jane ' ,
55+ 'from ' => 'Jeff ' ,
56+ 'title ' => 'Clean the house ' ,
57+ ],
58+ ],
59+ ],
60+ ];
61+
62+ $ this ->assertEquals ($ expected , xml_to_array ($ xml ));
63+ }
3464}
You can’t perform that action at this time.
0 commit comments