Rearrange tests to be a directory of samples, all tested the same way
This commit is contained in:
parent
0fb1c9b166
commit
60afe7f7b9
13 changed files with 230 additions and 264 deletions
|
@ -13,7 +13,10 @@
|
|||
"role": "Contributor"
|
||||
}],
|
||||
"autoload": {
|
||||
"classmap": ["src/"]
|
||||
"files": [
|
||||
"src/simplexml_dump.php",
|
||||
"src/simplexml_tree.php"
|
||||
]
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<phpunit
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.1/phpunit.xsd"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
bootstrap="vendor/autoload.php"
|
||||
backupGlobals="true"
|
||||
verbose="true"
|
||||
colors="true"
|
||||
|
|
12
tests/dump-output/basic
Normal file
12
tests/dump-output/basic
Normal file
|
@ -0,0 +1,12 @@
|
|||
SimpleXML object (1 item)
|
||||
[
|
||||
Element {
|
||||
Name: 'movies'
|
||||
String Content: '
|
||||
|
||||
'
|
||||
Content in Default Namespace
|
||||
Children: 1 - 1 'movie'
|
||||
Attributes: 0
|
||||
}
|
||||
]
|
15
tests/dump-output/basic-default-ns
Normal file
15
tests/dump-output/basic-default-ns
Normal file
|
@ -0,0 +1,15 @@
|
|||
SimpleXML object (1 item)
|
||||
[
|
||||
Element {
|
||||
Namespace: 'https://github.com/IMSoP/simplexml_debug'
|
||||
(Default Namespace)
|
||||
Name: 'movies'
|
||||
String Content: '
|
||||
|
||||
'
|
||||
Content in Default Namespace
|
||||
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
|
||||
Children: 1 - 1 'movie'
|
||||
Attributes: 0
|
||||
}
|
||||
]
|
13
tests/dump-output/basic-ns
Normal file
13
tests/dump-output/basic-ns
Normal file
|
@ -0,0 +1,13 @@
|
|||
SimpleXML object (1 item)
|
||||
[
|
||||
Element {
|
||||
Name: 'movies'
|
||||
String Content: '
|
||||
|
||||
'
|
||||
Content in Namespace test
|
||||
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
|
||||
Children: 1 - 1 'movie'
|
||||
Attributes: 0
|
||||
}
|
||||
]
|
26
tests/input/basic-default-ns.xml
Normal file
26
tests/input/basic-default-ns.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" ?>
|
||||
<movies xmlns="https://github.com/IMSoP/simplexml_debug">
|
||||
<movie>
|
||||
<title>PHP: Behind the Parser</title>
|
||||
<characters>
|
||||
<character>
|
||||
<name>Ms. Coder</name>
|
||||
<actor>Onlivia Actora</actor>
|
||||
</character>
|
||||
<character>
|
||||
<name>Mr. Coder</name>
|
||||
<actor>El ActÓr</actor>
|
||||
</character>
|
||||
</characters>
|
||||
<plot>
|
||||
So, this language. It's like, a programming language.
|
||||
Or is it a scripting language? All is revealed in this
|
||||
thrilling horror spoof of a documentary.
|
||||
</plot>
|
||||
<great-lines>
|
||||
<line>PHP solves all my web problems</line>
|
||||
</great-lines>
|
||||
<rating type="thumbs">7</rating>
|
||||
<rating type="stars">5</rating>
|
||||
</movie>
|
||||
</movies>
|
26
tests/input/basic-ns.xml
Normal file
26
tests/input/basic-ns.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" ?>
|
||||
<movies xmlns:test="https://github.com/IMSoP/simplexml_debug">
|
||||
<test:movie>
|
||||
<test:title>PHP: Behind the Parser</test:title>
|
||||
<test:characters>
|
||||
<test:character>
|
||||
<test:name>Ms. Coder</test:name>
|
||||
<test:actor>Onlivia Actora</test:actor>
|
||||
</test:character>
|
||||
<test:character>
|
||||
<test:name>Mr. Coder</test:name>
|
||||
<test:actor>El ActÓr</test:actor>
|
||||
</test:character>
|
||||
</test:characters>
|
||||
<test:plot>
|
||||
So, this language. It's like, a programming language.
|
||||
Or is it a scripting language? All is revealed in this
|
||||
thrilling horror spoof of a documentary.
|
||||
</test:plot>
|
||||
<test:great-lines>
|
||||
<test:line>PHP solves all my web problems</test:line>
|
||||
</test:great-lines>
|
||||
<test:rating type="thumbs">7</test:rating>
|
||||
<test:rating type="stars">5</test:rating>
|
||||
</test:movie>
|
||||
</movies>
|
26
tests/input/basic.xml
Normal file
26
tests/input/basic.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" ?>
|
||||
<movies>
|
||||
<movie>
|
||||
<title>PHP: Behind the Parser</title>
|
||||
<characters>
|
||||
<character>
|
||||
<name>Ms. Coder</name>
|
||||
<actor>Onlivia Actora</actor>
|
||||
</character>
|
||||
<character>
|
||||
<name>Mr. Coder</name>
|
||||
<actor>El ActÓr</actor>
|
||||
</character>
|
||||
</characters>
|
||||
<plot>
|
||||
So, this language. It's like, a programming language.
|
||||
Or is it a scripting language? All is revealed in this
|
||||
thrilling horror spoof of a documentary.
|
||||
</plot>
|
||||
<great-lines>
|
||||
<line>PHP solves all my web problems</line>
|
||||
</great-lines>
|
||||
<rating type="thumbs">7</rating>
|
||||
<rating type="stars">5</rating>
|
||||
</movie>
|
||||
</movies>
|
|
@ -1,131 +1,34 @@
|
|||
<?php
|
||||
|
||||
class simplexml_dump_Test extends simplexml_dump_bootstrap
|
||||
class simplexml_dump_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
public function loadExamples()
|
||||
{
|
||||
$this->expected = "SimpleXML object (1 item)
|
||||
[
|
||||
Element {
|
||||
Name: 'movies'
|
||||
String Content: '
|
||||
$test_cases = array();
|
||||
|
||||
'
|
||||
Content in Default Namespace
|
||||
Children: 1 - 1 'movie'
|
||||
Attributes: 0
|
||||
}
|
||||
]
|
||||
";
|
||||
|
||||
$this->expected_default_NS = "SimpleXML object (1 item)
|
||||
[
|
||||
Element {
|
||||
Namespace: 'https://github.com/IMSoP/simplexml_debug'
|
||||
(Default Namespace)
|
||||
Name: 'movies'
|
||||
String Content: '
|
||||
|
||||
'
|
||||
Content in Default Namespace
|
||||
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
|
||||
Children: 1 - 1 'movie'
|
||||
Attributes: 0
|
||||
}
|
||||
]
|
||||
";
|
||||
|
||||
$this->expected_named_NS = "SimpleXML object (1 item)
|
||||
[
|
||||
Element {
|
||||
Name: 'movies'
|
||||
String Content: '
|
||||
|
||||
'
|
||||
Content in Namespace test
|
||||
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
|
||||
Children: 1 - 1 'movie'
|
||||
Attributes: 0
|
||||
}
|
||||
]
|
||||
";
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testDump()
|
||||
foreach ( new DirectoryIterator(__DIR__ . '/dump-output') as $fileInfo )
|
||||
{
|
||||
ob_start();
|
||||
simplexml_dump($this->simpleXML);
|
||||
$return = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertEquals($this->expected, $return);
|
||||
if($fileInfo->isDot()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
public function testDumpReturn()
|
||||
$filename = $fileInfo->getFilename();
|
||||
|
||||
$test_cases[$filename] = array(
|
||||
file_get_contents(__DIR__ . '/input/' . $filename . '.xml'),
|
||||
file_get_contents(__DIR__ . '/dump-output/' . $filename)
|
||||
);
|
||||
}
|
||||
|
||||
return $test_cases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider loadExamples
|
||||
*/
|
||||
public function testDumpReturn($xml, $expected_output)
|
||||
{
|
||||
$return = simplexml_dump($this->simpleXML, true);
|
||||
$this->assertEquals($this->expected, $return);
|
||||
}
|
||||
|
||||
public function testDumpWithDefaultNS()
|
||||
{
|
||||
$return = simplexml_dump($this->simpleXML_default_NS, true);
|
||||
$this->assertEquals($this->expected_default_NS, $return);
|
||||
}
|
||||
|
||||
public function testDumpWithNamedNS()
|
||||
{
|
||||
$return = simplexml_dump($this->simpleXML_named_NS, true);
|
||||
$this->assertEquals($this->expected_named_NS, $return);
|
||||
}
|
||||
|
||||
public function testDumpAttributeWithNamedNS()
|
||||
{
|
||||
$xml = '<parent xmlns:ns="ns"><ns:child ns:foo="bar" /></parent>';
|
||||
$sxml = simplexml_load_string($xml);
|
||||
|
||||
$return = simplexml_dump($sxml->children('ns', true)->child->attributes('ns'), true);
|
||||
|
||||
$expected = "SimpleXML object (1 item)
|
||||
[
|
||||
Attribute {
|
||||
Namespace: 'ns'
|
||||
Namespace Alias: 'ns'
|
||||
Name: 'foo'
|
||||
Value: 'bar'
|
||||
}
|
||||
]
|
||||
";
|
||||
|
||||
$this->assertEquals($expected, $return);
|
||||
}
|
||||
|
||||
public function testDumpMultipleAttributes()
|
||||
{
|
||||
$xml = '<parent xmlns:ns="ns"><child ns:one="1" ns:two="2" ns:three="3" /></parent>';
|
||||
$sxml = simplexml_load_string($xml);
|
||||
|
||||
$return = simplexml_dump($sxml->child, true);
|
||||
|
||||
$expected = "SimpleXML object (1 item)
|
||||
[
|
||||
Element {
|
||||
Namespace: 'ns'
|
||||
Namespace Alias: 'ns'
|
||||
Name: 'child'
|
||||
String Content: ''
|
||||
Content in Namespace ns
|
||||
Namespace URI: 'ns'
|
||||
Children: 0
|
||||
Attributes: 3 - 'one', 'two', 'three'
|
||||
}
|
||||
]
|
||||
";
|
||||
|
||||
$this->assertEquals($expected, $return);
|
||||
$return = simplexml_dump(simplexml_load_string($xml), true);
|
||||
$this->assertSame($expected_output, $return);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,149 +1,34 @@
|
|||
<?php
|
||||
|
||||
class simplexml_tree_Test extends simplexml_dump_bootstrap
|
||||
class simplexml_tree_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
public function loadExamples()
|
||||
{
|
||||
$this->expected = "SimpleXML object (1 item)
|
||||
[0] // <movies>
|
||||
->movie[0]
|
||||
->title[0]
|
||||
->characters[0]
|
||||
->character[0]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->character[1]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->plot[0]
|
||||
->great-lines[0]
|
||||
->line[0]
|
||||
->rating[0]
|
||||
['type']
|
||||
->rating[1]
|
||||
['type']
|
||||
";
|
||||
$test_cases = array();
|
||||
|
||||
$this->expected_default_NS = "SimpleXML object (1 item)
|
||||
[0] // <movies>
|
||||
->movie[0]
|
||||
->title[0]
|
||||
->characters[0]
|
||||
->character[0]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->character[1]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->plot[0]
|
||||
->great-lines[0]
|
||||
->line[0]
|
||||
->rating[0]
|
||||
['type']
|
||||
->rating[1]
|
||||
['type']
|
||||
";
|
||||
|
||||
$this->expected_named_NS = "SimpleXML object (1 item)
|
||||
[0] // <movies>
|
||||
->children('test', true)
|
||||
->movie[0]
|
||||
->title[0]
|
||||
->characters[0]
|
||||
->character[0]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->character[1]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->plot[0]
|
||||
->great-lines[0]
|
||||
->line[0]
|
||||
->rating[0]
|
||||
->attributes('', true)
|
||||
->type
|
||||
->rating[1]
|
||||
->attributes('', true)
|
||||
->type
|
||||
";
|
||||
|
||||
parent::setUp();
|
||||
foreach ( new DirectoryIterator(__DIR__ . '/dump-output') as $fileInfo )
|
||||
{
|
||||
if($fileInfo->isDot()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
public function testTree()
|
||||
$filename = $fileInfo->getFilename();
|
||||
|
||||
$test_cases[$filename] = array(
|
||||
file_get_contents(__DIR__ . '/input/' . $filename . '.xml'),
|
||||
file_get_contents(__DIR__ . '/tree-output/' . $filename)
|
||||
);
|
||||
}
|
||||
|
||||
return $test_cases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider loadExamples
|
||||
*/
|
||||
public function testTreeReturn($xml, $expected_output)
|
||||
{
|
||||
ob_start();
|
||||
simplexml_tree($this->simpleXML);
|
||||
$return = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertEquals($this->expected, $return);
|
||||
}
|
||||
|
||||
public function testTreeIncludeStringContent()
|
||||
{
|
||||
ob_start();
|
||||
simplexml_tree($this->simpleXML, true);
|
||||
$return = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$expected = "SimpleXML object (1 item)
|
||||
[0] // <movies>
|
||||
(string) '' (9 chars)
|
||||
->movie[0]
|
||||
(string) '' (41 chars)
|
||||
->title[0]
|
||||
(string) 'PHP: Behind the...' (22 chars)
|
||||
->characters[0]
|
||||
(string) '' (20 chars)
|
||||
->character[0]
|
||||
(string) '' (23 chars)
|
||||
->name[0]
|
||||
(string) 'Ms. Coder' (9 chars)
|
||||
->actor[0]
|
||||
(string) 'Onlivia Actora' (14 chars)
|
||||
->character[1]
|
||||
(string) '' (23 chars)
|
||||
->name[0]
|
||||
(string) 'Mr. Coder' (9 chars)
|
||||
->actor[0]
|
||||
(string) 'El ActÓr' (9 chars)
|
||||
->plot[0]
|
||||
(string) 'So, this langua...' (174 chars)
|
||||
->great-lines[0]
|
||||
(string) '' (13 chars)
|
||||
->line[0]
|
||||
(string) 'PHP solves all ...' (30 chars)
|
||||
->rating[0]
|
||||
(string) '7' (1 chars)
|
||||
['type']
|
||||
(string) 'thumbs' (6 chars)
|
||||
->rating[1]
|
||||
(string) '5' (1 chars)
|
||||
['type']
|
||||
(string) 'stars' (5 chars)
|
||||
";
|
||||
|
||||
$this->assertEquals($expected, $return);
|
||||
}
|
||||
|
||||
public function testTreeReturn()
|
||||
{
|
||||
$return = simplexml_tree($this->simpleXML, false, true);
|
||||
$this->assertEquals($this->expected, $return);
|
||||
}
|
||||
|
||||
public function testTreeWithDefaultNS()
|
||||
{
|
||||
$return = simplexml_tree($this->simpleXML_default_NS, false, true);
|
||||
$this->assertEquals($this->expected_default_NS, $return);
|
||||
}
|
||||
|
||||
public function testTreeWithNamedNS()
|
||||
{
|
||||
$return = simplexml_tree($this->simpleXML_named_NS, false, true);
|
||||
$this->assertEquals($this->expected_named_NS, $return);
|
||||
$return = simplexml_tree(simplexml_load_string($xml), false, true);
|
||||
$this->assertSame($expected_output, $return);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
18
tests/tree-output/basic
Normal file
18
tests/tree-output/basic
Normal file
|
@ -0,0 +1,18 @@
|
|||
SimpleXML object (1 item)
|
||||
[0] // <movies>
|
||||
->movie[0]
|
||||
->title[0]
|
||||
->characters[0]
|
||||
->character[0]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->character[1]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->plot[0]
|
||||
->great-lines[0]
|
||||
->line[0]
|
||||
->rating[0]
|
||||
['type']
|
||||
->rating[1]
|
||||
['type']
|
18
tests/tree-output/basic-default-ns
Normal file
18
tests/tree-output/basic-default-ns
Normal file
|
@ -0,0 +1,18 @@
|
|||
SimpleXML object (1 item)
|
||||
[0] // <movies>
|
||||
->movie[0]
|
||||
->title[0]
|
||||
->characters[0]
|
||||
->character[0]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->character[1]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->plot[0]
|
||||
->great-lines[0]
|
||||
->line[0]
|
||||
->rating[0]
|
||||
['type']
|
||||
->rating[1]
|
||||
['type']
|
21
tests/tree-output/basic-ns
Normal file
21
tests/tree-output/basic-ns
Normal file
|
@ -0,0 +1,21 @@
|
|||
SimpleXML object (1 item)
|
||||
[0] // <movies>
|
||||
->children('test', true)
|
||||
->movie[0]
|
||||
->title[0]
|
||||
->characters[0]
|
||||
->character[0]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->character[1]
|
||||
->name[0]
|
||||
->actor[0]
|
||||
->plot[0]
|
||||
->great-lines[0]
|
||||
->line[0]
|
||||
->rating[0]
|
||||
->attributes('', true)
|
||||
->type
|
||||
->rating[1]
|
||||
->attributes('', true)
|
||||
->type
|
Loading…
Add table
Add a link
Reference in a new issue