Skip to content

Commit f3238d9

Browse files
committed
Merge branch 'xml-oriented-tests'
2 parents 2e11676 + 96c89e2 commit f3238d9

File tree

15 files changed

+282
-273
lines changed

15 files changed

+282
-273
lines changed

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<phpunit
22
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.1/phpunit.xsd"
4-
bootstrap="tests/bootstrap.php"
4+
bootstrap="vendor/autoload.php"
55
backupGlobals="true"
66
verbose="true"
77
colors="true"

tests/dump-output/basic

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
SimpleXML object (1 item)
2+
[
3+
Element {
4+
Name: 'movies'
5+
String Content: '
6+
7+
'
8+
Content in Default Namespace
9+
Children: 1 - 1 'movie'
10+
Attributes: 0
11+
}
12+
]

tests/dump-output/basic-default-ns

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
SimpleXML object (1 item)
2+
[
3+
Element {
4+
Namespace: 'https://github.com/IMSoP/simplexml_debug'
5+
(Default Namespace)
6+
Name: 'movies'
7+
String Content: '
8+
9+
'
10+
Content in Default Namespace
11+
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
12+
Children: 1 - 1 'movie'
13+
Attributes: 0
14+
}
15+
]

tests/dump-output/basic-ns

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SimpleXML object (1 item)
2+
[
3+
Element {
4+
Name: 'movies'
5+
String Content: '
6+
7+
'
8+
Content in Namespace test
9+
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
10+
Children: 1 - 1 'movie'
11+
Attributes: 0
12+
}
13+
]

tests/dump-output/soap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SimpleXML object (1 item)
2+
[
3+
Element {
4+
Namespace: 'http://schemas.xmlsoap.org/soap/envelope/'
5+
Namespace Alias: 'soap'
6+
Name: 'Envelope'
7+
String Content: '
8+
9+
10+
'
11+
Content in Namespace soap
12+
Namespace URI: 'http://schemas.xmlsoap.org/soap/envelope/'
13+
Children: 2 - 1 'Body', 1 'Header'
14+
Attributes: 0
15+
}
16+
]

tests/input/basic-default-ns.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" ?>
2+
<movies xmlns="https://github.com/IMSoP/simplexml_debug">
3+
<movie>
4+
<title>PHP: Behind the Parser</title>
5+
<characters>
6+
<character>
7+
<name>Ms. Coder</name>
8+
<actor>Onlivia Actora</actor>
9+
</character>
10+
<character>
11+
<name>Mr. Coder</name>
12+
<actor>El Act&#211;r</actor>
13+
</character>
14+
</characters>
15+
<plot>
16+
So, this language. It's like, a programming language.
17+
Or is it a scripting language? All is revealed in this
18+
thrilling horror spoof of a documentary.
19+
</plot>
20+
<great-lines>
21+
<line>PHP solves all my web problems</line>
22+
</great-lines>
23+
<rating type="thumbs">7</rating>
24+
<rating type="stars">5</rating>
25+
</movie>
26+
</movies>

tests/input/basic-ns.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" ?>
2+
<movies xmlns:test="https://github.com/IMSoP/simplexml_debug">
3+
<test:movie>
4+
<test:title>PHP: Behind the Parser</test:title>
5+
<test:characters>
6+
<test:character>
7+
<test:name>Ms. Coder</test:name>
8+
<test:actor>Onlivia Actora</test:actor>
9+
</test:character>
10+
<test:character>
11+
<test:name>Mr. Coder</test:name>
12+
<test:actor>El Act&#211;r</test:actor>
13+
</test:character>
14+
</test:characters>
15+
<test:plot>
16+
So, this language. It's like, a programming language.
17+
Or is it a scripting language? All is revealed in this
18+
thrilling horror spoof of a documentary.
19+
</test:plot>
20+
<test:great-lines>
21+
<test:line>PHP solves all my web problems</test:line>
22+
</test:great-lines>
23+
<test:rating type="thumbs">7</test:rating>
24+
<test:rating type="stars">5</test:rating>
25+
</test:movie>
26+
</movies>

tests/input/basic.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" ?>
2+
<movies>
3+
<movie>
4+
<title>PHP: Behind the Parser</title>
5+
<characters>
6+
<character>
7+
<name>Ms. Coder</name>
8+
<actor>Onlivia Actora</actor>
9+
</character>
10+
<character>
11+
<name>Mr. Coder</name>
12+
<actor>El Act&#211;r</actor>
13+
</character>
14+
</characters>
15+
<plot>
16+
So, this language. It's like, a programming language.
17+
Or is it a scripting language? All is revealed in this
18+
thrilling horror spoof of a documentary.
19+
</plot>
20+
<great-lines>
21+
<line>PHP solves all my web problems</line>
22+
</great-lines>
23+
<rating type="thumbs">7</rating>
24+
<rating type="stars">5</rating>
25+
</movie>
26+
</movies>

tests/input/soap.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" ?>
2+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
3+
<soap:Header>
4+
<s:credentials xmlns:s="http://example.org/security">
5+
<username>test</username>
6+
<password>letmein</password>
7+
</s:credentials>
8+
</soap:Header>
9+
<soap:Body>
10+
<tns:DoSomething xmlns:tns="http://example.org/some-soap-service">
11+
<from>A</from>
12+
<to>B</to>
13+
</tns:DoSomething>
14+
</soap:Body>
15+
</soap:Envelope>

tests/simplexml_dump_Test.php

Lines changed: 30 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,34 @@
11
<?php
22

3-
class simplexml_dump_Test extends simplexml_dump_bootstrap
3+
class simplexml_dump_test extends PHPUnit_Framework_TestCase
44
{
5-
public function setUp()
6-
{
7-
$this->expected = "SimpleXML object (1 item)
8-
[
9-
Element {
10-
Name: 'movies'
11-
String Content: '
12-
13-
'
14-
Content in Default Namespace
15-
Children: 1 - 1 'movie'
16-
Attributes: 0
17-
}
18-
]
19-
";
20-
21-
$this->expected_default_NS = "SimpleXML object (1 item)
22-
[
23-
Element {
24-
Namespace: 'https://github.com/IMSoP/simplexml_debug'
25-
(Default Namespace)
26-
Name: 'movies'
27-
String Content: '
28-
29-
'
30-
Content in Default Namespace
31-
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
32-
Children: 1 - 1 'movie'
33-
Attributes: 0
34-
}
35-
]
36-
";
37-
38-
$this->expected_named_NS = "SimpleXML object (1 item)
39-
[
40-
Element {
41-
Name: 'movies'
42-
String Content: '
43-
44-
'
45-
Content in Namespace test
46-
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
47-
Children: 1 - 1 'movie'
48-
Attributes: 0
49-
}
50-
]
51-
";
52-
53-
parent::setUp();
54-
}
55-
56-
public function testDump()
57-
{
58-
ob_start();
59-
simplexml_dump($this->simpleXML);
60-
$return = ob_get_contents();
61-
ob_end_clean();
62-
63-
$this->assertEquals($this->expected, $return);
64-
}
65-
66-
public function testDumpReturn()
67-
{
68-
$return = simplexml_dump($this->simpleXML, true);
69-
$this->assertEquals($this->expected, $return);
70-
}
71-
72-
public function testDumpWithDefaultNS()
73-
{
74-
$return = simplexml_dump($this->simpleXML_default_NS, true);
75-
$this->assertEquals($this->expected_default_NS, $return);
76-
}
77-
78-
public function testDumpWithNamedNS()
79-
{
80-
$return = simplexml_dump($this->simpleXML_named_NS, true);
81-
$this->assertEquals($this->expected_named_NS, $return);
82-
}
83-
84-
public function testDumpAttributeWithNamedNS()
85-
{
86-
$xml = '<parent xmlns:ns="ns"><ns:child ns:foo="bar" /></parent>';
87-
$sxml = simplexml_load_string($xml);
88-
89-
$return = simplexml_dump($sxml->children('ns', true)->child->attributes('ns'), true);
90-
91-
$expected = "SimpleXML object (1 item)
92-
[
93-
Attribute {
94-
Namespace: 'ns'
95-
Namespace Alias: 'ns'
96-
Name: 'foo'
97-
Value: 'bar'
98-
}
99-
]
100-
";
101-
102-
$this->assertEquals($expected, $return);
103-
}
104-
105-
public function testDumpMultipleAttributes()
106-
{
107-
$xml = '<parent xmlns:ns="ns"><child ns:one="1" ns:two="2" ns:three="3" /></parent>';
108-
$sxml = simplexml_load_string($xml);
109-
110-
$return = simplexml_dump($sxml->child, true);
111-
112-
$expected = "SimpleXML object (1 item)
113-
[
114-
Element {
115-
Namespace: 'ns'
116-
Namespace Alias: 'ns'
117-
Name: 'child'
118-
String Content: ''
119-
Content in Namespace ns
120-
Namespace URI: 'ns'
121-
Children: 0
122-
Attributes: 3 - 'one', 'two', 'three'
123-
}
124-
]
125-
";
126-
127-
$this->assertEquals($expected, $return);
128-
}
5+
public function loadExamples()
6+
{
7+
$test_cases = array();
8+
9+
foreach ( new DirectoryIterator(__DIR__ . '/dump-output') as $fileInfo )
10+
{
11+
if($fileInfo->isDot()) {
12+
continue;
13+
}
14+
15+
$filename = $fileInfo->getFilename();
16+
17+
$test_cases[$filename] = array(
18+
file_get_contents(__DIR__ . '/input/' . $filename . '.xml'),
19+
file_get_contents(__DIR__ . '/dump-output/' . $filename)
20+
);
21+
}
22+
23+
return $test_cases;
24+
}
25+
26+
/**
27+
* @dataProvider loadExamples
28+
*/
29+
public function testDumpReturn($xml, $expected_output)
30+
{
31+
$return = simplexml_dump(simplexml_load_string($xml), true);
32+
$this->assertSame($expected_output, $return);
33+
}
12934
}
130-
131-
?>

0 commit comments

Comments
 (0)