From 60afe7f7b9ea21336fec34e78675a260b92f2d19 Mon Sep 17 00:00:00 2001 From: Rowan Collins Date: Thu, 9 Nov 2017 20:02:34 +0000 Subject: [PATCH 1/2] Rearrange tests to be a directory of samples, all tested the same way --- composer.json | 5 +- phpunit.xml | 2 +- tests/dump-output/basic | 12 +++ tests/dump-output/basic-default-ns | 15 +++ tests/dump-output/basic-ns | 13 +++ tests/input/basic-default-ns.xml | 26 +++++ tests/input/basic-ns.xml | 26 +++++ tests/input/basic.xml | 26 +++++ tests/simplexml_dump_Test.php | 147 +++++-------------------- tests/simplexml_tree_Test.php | 165 +++++------------------------ tests/tree-output/basic | 18 ++++ tests/tree-output/basic-default-ns | 18 ++++ tests/tree-output/basic-ns | 21 ++++ 13 files changed, 230 insertions(+), 264 deletions(-) create mode 100644 tests/dump-output/basic create mode 100644 tests/dump-output/basic-default-ns create mode 100644 tests/dump-output/basic-ns create mode 100644 tests/input/basic-default-ns.xml create mode 100644 tests/input/basic-ns.xml create mode 100644 tests/input/basic.xml create mode 100644 tests/tree-output/basic create mode 100644 tests/tree-output/basic-default-ns create mode 100644 tests/tree-output/basic-ns diff --git a/composer.json b/composer.json index 41839c8..a65cfa1 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,10 @@ "role": "Contributor" }], "autoload": { - "classmap": ["src/"] + "files": [ + "src/simplexml_dump.php", + "src/simplexml_tree.php" + ] }, "require-dev": { "phpunit/phpunit": "^4.8" diff --git a/phpunit.xml b/phpunit.xml index 7d97a80..ea59267 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ + + + PHP: Behind the Parser + + + Ms. Coder + Onlivia Actora + + + Mr. Coder + El ActÓr + + + + 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. + + + PHP solves all my web problems + + 7 + 5 + + \ No newline at end of file diff --git a/tests/input/basic-ns.xml b/tests/input/basic-ns.xml new file mode 100644 index 0000000..9b3afbd --- /dev/null +++ b/tests/input/basic-ns.xml @@ -0,0 +1,26 @@ + + + + PHP: Behind the Parser + + + Ms. Coder + Onlivia Actora + + + Mr. Coder + El ActÓr + + + + 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. + + + PHP solves all my web problems + + 7 + 5 + + \ No newline at end of file diff --git a/tests/input/basic.xml b/tests/input/basic.xml new file mode 100644 index 0000000..a1d4621 --- /dev/null +++ b/tests/input/basic.xml @@ -0,0 +1,26 @@ + + + + PHP: Behind the Parser + + + Ms. Coder + Onlivia Actora + + + Mr. Coder + El ActÓr + + + + 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. + + + PHP solves all my web problems + + 7 + 5 + + \ No newline at end of file diff --git a/tests/simplexml_dump_Test.php b/tests/simplexml_dump_Test.php index 506fea8..bae27eb 100644 --- a/tests/simplexml_dump_Test.php +++ b/tests/simplexml_dump_Test.php @@ -1,131 +1,34 @@ expected = "SimpleXML object (1 item) -[ - Element { - Name: 'movies' - String Content: ' - - ' - Content in Default Namespace - Children: 1 - 1 'movie' - Attributes: 0 - } -] -"; + public function loadExamples() + { + $test_cases = array(); - $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 - } -] -"; + foreach ( new DirectoryIterator(__DIR__ . '/dump-output') as $fileInfo ) + { + if($fileInfo->isDot()) { + continue; + } - $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 - } -] -"; + $filename = $fileInfo->getFilename(); - parent::setUp(); - } + $test_cases[$filename] = array( + file_get_contents(__DIR__ . '/input/' . $filename . '.xml'), + file_get_contents(__DIR__ . '/dump-output/' . $filename) + ); + } - public function testDump() - { - ob_start(); - simplexml_dump($this->simpleXML); - $return = ob_get_contents(); - ob_end_clean(); + return $test_cases; + } - $this->assertEquals($this->expected, $return); - } - - public function testDumpReturn() - { - $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 = ''; - $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 = ''; - $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); - } + /** + * @dataProvider loadExamples + */ + public function testDumpReturn($xml, $expected_output) + { + $return = simplexml_dump(simplexml_load_string($xml), true); + $this->assertSame($expected_output, $return); + } } - -?> diff --git a/tests/simplexml_tree_Test.php b/tests/simplexml_tree_Test.php index 786a8ad..1ab6926 100644 --- a/tests/simplexml_tree_Test.php +++ b/tests/simplexml_tree_Test.php @@ -1,149 +1,34 @@ expected = "SimpleXML object (1 item) -[0] // - ->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'] -"; + public function loadExamples() + { + $test_cases = array(); - $this->expected_default_NS = "SimpleXML object (1 item) -[0] // - ->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'] -"; + foreach ( new DirectoryIterator(__DIR__ . '/dump-output') as $fileInfo ) + { + if($fileInfo->isDot()) { + continue; + } - $this->expected_named_NS = "SimpleXML object (1 item) -[0] // - ->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 -"; + $filename = $fileInfo->getFilename(); - parent::setUp(); - } + $test_cases[$filename] = array( + file_get_contents(__DIR__ . '/input/' . $filename . '.xml'), + file_get_contents(__DIR__ . '/tree-output/' . $filename) + ); + } - public function testTree() - { - ob_start(); - simplexml_tree($this->simpleXML); - $return = ob_get_contents(); - ob_end_clean(); + return $test_cases; + } - $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] // - (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); - } + /** + * @dataProvider loadExamples + */ + public function testTreeReturn($xml, $expected_output) + { + $return = simplexml_tree(simplexml_load_string($xml), false, true); + $this->assertSame($expected_output, $return); + } } - -?> diff --git a/tests/tree-output/basic b/tests/tree-output/basic new file mode 100644 index 0000000..69be6c0 --- /dev/null +++ b/tests/tree-output/basic @@ -0,0 +1,18 @@ +SimpleXML object (1 item) +[0] // + ->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'] diff --git a/tests/tree-output/basic-default-ns b/tests/tree-output/basic-default-ns new file mode 100644 index 0000000..69be6c0 --- /dev/null +++ b/tests/tree-output/basic-default-ns @@ -0,0 +1,18 @@ +SimpleXML object (1 item) +[0] // + ->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'] diff --git a/tests/tree-output/basic-ns b/tests/tree-output/basic-ns new file mode 100644 index 0000000..46179c3 --- /dev/null +++ b/tests/tree-output/basic-ns @@ -0,0 +1,21 @@ +SimpleXML object (1 item) +[0] // + ->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 From 96c89e26603d01b02d43f2117ebd3949b8283c2a Mon Sep 17 00:00:00 2001 From: Rowan Collins Date: Thu, 9 Nov 2017 20:39:46 +0000 Subject: [PATCH 2/2] Add SOAP examples, with failing test for Issue #4 --- tests/dump-output/soap | 16 ++++++++++++++++ tests/input/soap.xml | 15 +++++++++++++++ tests/tree-output/soap | 15 +++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/dump-output/soap create mode 100644 tests/input/soap.xml create mode 100644 tests/tree-output/soap diff --git a/tests/dump-output/soap b/tests/dump-output/soap new file mode 100644 index 0000000..e1e31a2 --- /dev/null +++ b/tests/dump-output/soap @@ -0,0 +1,16 @@ +SimpleXML object (1 item) +[ + Element { + Namespace: 'http://schemas.xmlsoap.org/soap/envelope/' + Namespace Alias: 'soap' + Name: 'Envelope' + String Content: ' + + +' + Content in Namespace soap + Namespace URI: 'http://schemas.xmlsoap.org/soap/envelope/' + Children: 2 - 1 'Body', 1 'Header' + Attributes: 0 + } +] diff --git a/tests/input/soap.xml b/tests/input/soap.xml new file mode 100644 index 0000000..cf210f0 --- /dev/null +++ b/tests/input/soap.xml @@ -0,0 +1,15 @@ + + + + + test + letmein + + + + + A + B + + + diff --git a/tests/tree-output/soap b/tests/tree-output/soap new file mode 100644 index 0000000..d212f00 --- /dev/null +++ b/tests/tree-output/soap @@ -0,0 +1,15 @@ +SimpleXML object (1 item) +[0] // + ->children('soap', true) + ->Header[0] + ->children('s', true) + ->credentials[0] + ->children('', true) + ->username[0] + ->password[0] + ->Body[0] + ->children('tns', true) + ->DoSomething[0] + ->children('', true) + ->from[0] + ->to[0]