From 75acba318ddb2e3933d06cf29a5504ea0737cae0 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Thu, 7 Aug 2014 22:47:07 -0400 Subject: [PATCH 1/4] Started on some unit tests. --- tests/bootstrap.php | 68 +++++++++++++++++++++++++++++++++++ tests/simplexml_dump_Test.php | 62 ++++++++++++++++++++++++++++++++ tests/simplexml_tree_Test.php | 0 3 files changed, 130 insertions(+) create mode 100644 tests/bootstrap.php create mode 100644 tests/simplexml_dump_Test.php create mode 100644 tests/simplexml_tree_Test.php diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..3be9ba2 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,68 @@ +simpleXML = simplexml_load_string(' + + + 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 + + + '); + + $this->simpleXML_NS = simplexml_load_string(' + + + 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 + + + '); + } +} + +?> diff --git a/tests/simplexml_dump_Test.php b/tests/simplexml_dump_Test.php new file mode 100644 index 0000000..d29506f --- /dev/null +++ b/tests/simplexml_dump_Test.php @@ -0,0 +1,62 @@ +expected = "SimpleXML object (1 item) +[ + Element { + Name: 'movies' + String Content: ' + + ' + Content in Default Namespace + Children: 1 - 1 'movie' + Attributes: 0 + } +] +"; + + $this->expected_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() + { + ob_start(); + simplexml_dump($this->simpleXML); + $return = ob_get_contents(); + ob_end_clean(); + + $this->assertEquals($this->expected, $return); + } + + public function testDumpReturn() + { + $return = simplexml_dump($this->simpleXML, true); + $this->assertEquals($this->expected, $return); + } + + public function testDumpWithNS() + { + $return = simplexml_dump($this->simpleXML_NS, true); + $this->assertEquals($this->expected_NS, $return); + } +} + +?> diff --git a/tests/simplexml_tree_Test.php b/tests/simplexml_tree_Test.php new file mode 100644 index 0000000..e69de29 From af30ba47b689b9172b04cdb3871d9f2142a12373 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Fri, 8 Aug 2014 22:16:54 -0400 Subject: [PATCH 2/4] Working on better code coverage Added a new test that gets us up to 80% coverage. Still a ways to go. --- tests/simplexml_dump_Test.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/simplexml_dump_Test.php b/tests/simplexml_dump_Test.php index d29506f..741316c 100644 --- a/tests/simplexml_dump_Test.php +++ b/tests/simplexml_dump_Test.php @@ -57,6 +57,27 @@ class simplexml_dump_Test extends simplexml_dump_bootstrap $return = simplexml_dump($this->simpleXML_NS, true); $this->assertEquals($this->expected_NS, $return); } + + public function testDumpWithSingleNodeWithAttributesAndNS() + { + $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); + } } ?> From 3cad2648436adf14ddcf9a77eef3246de15a5dcd Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Sat, 9 Aug 2014 11:36:04 -0400 Subject: [PATCH 3/4] Unit tests for dump Got coverage up to 90% probably need @IMSoP to finish the rest as I'm having a hard time getting tests to hit the logic. --- tests/bootstrap.php | 30 +++++++++++++++++- tests/simplexml_dump_Test.php | 59 ++++++++++++++++++++++++++++++++--- 2 files changed, 83 insertions(+), 6 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3be9ba2..022f6c2 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -35,7 +35,35 @@ class simplexml_dump_bootstrap extends PHPUnit_Framework_TestCase '); - $this->simpleXML_NS = simplexml_load_string(' + $this->simpleXML_default_NS = simplexml_load_string(' + + + 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 + + + '); + + $this->simpleXML_named_NS = simplexml_load_string(' PHP: Behind the Parser diff --git a/tests/simplexml_dump_Test.php b/tests/simplexml_dump_Test.php index 741316c..5dd7610 100644 --- a/tests/simplexml_dump_Test.php +++ b/tests/simplexml_dump_Test.php @@ -18,7 +18,25 @@ class simplexml_dump_Test extends simplexml_dump_bootstrap ] "; - $this->expected_NS = "SimpleXML object (1 item) + $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' @@ -52,13 +70,19 @@ class simplexml_dump_Test extends simplexml_dump_bootstrap $this->assertEquals($this->expected, $return); } - public function testDumpWithNS() + public function testDumpWithDefaultNS() { - $return = simplexml_dump($this->simpleXML_NS, true); - $this->assertEquals($this->expected_NS, $return); + $return = simplexml_dump($this->simpleXML_default_NS, true); + $this->assertEquals($this->expected_default_NS, $return); } - public function testDumpWithSingleNodeWithAttributesAndNS() + 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); @@ -74,6 +98,31 @@ class simplexml_dump_Test extends simplexml_dump_bootstrap 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); From 53538b402e9bea3ba922a0a076a4801911391faf Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Mon, 18 Aug 2014 21:56:40 -0400 Subject: [PATCH 4/4] Got both dump and tree to 90% coverage --- tests/simplexml_dump_Test.php | 1 - tests/simplexml_tree_Test.php | 149 ++++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 1 deletion(-) diff --git a/tests/simplexml_dump_Test.php b/tests/simplexml_dump_Test.php index 5dd7610..506fea8 100644 --- a/tests/simplexml_dump_Test.php +++ b/tests/simplexml_dump_Test.php @@ -35,7 +35,6 @@ class simplexml_dump_Test extends simplexml_dump_bootstrap ] "; - $this->expected_named_NS = "SimpleXML object (1 item) [ Element { diff --git a/tests/simplexml_tree_Test.php b/tests/simplexml_tree_Test.php index e69de29..786a8ad 100644 --- a/tests/simplexml_tree_Test.php +++ b/tests/simplexml_tree_Test.php @@ -0,0 +1,149 @@ +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'] +"; + + $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'] +"; + + $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 +"; + + parent::setUp(); + } + + public function testTree() + { + 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] // + (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); + } +} + +?>