Skip to content

Commit

Permalink
Merge pull request #17 from jspeedz/development
Browse files Browse the repository at this point in the history
Add SimpleXMLElement dumper test, global method
  • Loading branch information
jspeedz committed Oct 3, 2019
2 parents 321cacb + bb141f5 commit 89401d7
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ Result:

`To be determined..`

### Dumping simple XML element objects
Converting and dumping SimpleXmlObjects into a readable string.

#### Example 1:

```php
dumpSimpleXmlElement(
simplexml_load_string('<?xml version="1.0" encoding="utf-8" ?><root><someElement>someValue</someElement></root>')
);
```
Result:

```SimpleXML object (1 item)
[
Element {
Name: 'root'
String Content: ''
Content in Default Namespace
Children: 1 - 1 'someElement'
Attributes: 0
}
]
```

## Utilities
### Timing a block of code
```php
Expand Down Expand Up @@ -93,6 +117,13 @@ if($this->container->getParameter('kernel.environment') === 'dev') {
}
```

```php
if($this->container->getParameter('kernel.environment') === 'dev') {
dumpSimpleXmlElement($END$);
die(__FILE__ . ':' . __LINE__);
}
```

## Install
Please only install this package for development:

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
"Jspeedz\\DebugPooper\\": "src/"
},
"files": [
"src/Component/VarDumper/Resources/functions/debugtimer.php",
"src/Component/VarDumper/Resources/functions/dump.php",
"src/Component/VarDumper/Resources/functions/dumpquery.php",
"src/Component/VarDumper/Resources/functions/dumprequest.php"
"src/Component/VarDumper/Resources/functions/dumprequest.php",
"src/Component/VarDumper/Resources/functions/dumpsimplexmlelement.php"
],
"exclude-from-classmap": [
"/Tests/"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
use Jspeedz\DebugPooper\Pooper\SimpleXmlElementDumper;

if(!function_exists('dumpSimpleXmlElement')) {
/**
* @param SimpleXMLElement $simpleXMLElement
* @param bool $return = false
*
* @return void
*
*/
function dumpSimpleXmlElement(SimpleXMLElement $simpleXMLElement, bool $return = false): void {
SimpleXmlElementDumper::dump($simpleXMLElement, $return);
}
}
38 changes: 38 additions & 0 deletions src/Tests/Pooper/SimpleXmlElementDumperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
namespace Jspeedz\DebugPooper\Tests\Pooper;

use Jspeedz\DebugPooper\Pooper\SimpleXmlElementDumper;
use PHPUnit\Framework\TestCase;

class SimpleXmlElementDumperTest extends TestCase {
public function testDumpReturnOutput() {
$element = simplexml_load_string('<?xml version="1.0" encoding="utf-8" ?>
<root>
<this>
<is>Some</is>
<test>
<that>Will validate</that>
</test>
<z our="dumper">xx</z>
</this>
</root>');

$result = SimpleXmlElementDumper::dump($element, true);
$result = str_replace("\n", "", $result);
$result = str_replace("\r", "", $result);

$expected = "SimpleXML object (1 item)[
Element {
Name: 'root'
String Content: '\n \n'
Content in Default Namespace
Children: 1 - 1 'this'
Attributes: 0
}
]";
$expected = str_replace("\n", "", $expected);
$expected = str_replace("\r", "", $expected);

$this->assertEquals($expected, $result);
}
}

0 comments on commit 89401d7

Please sign in to comment.