Skip to content

add simple tests #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* text=auto

/tests
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml export-ignore
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ This will result in the following.
Reference
----
More complete references can be found here
http://www.lalit.org/lab/convert-xml-to-array-in-php-xml2array/
http://www.lalit.org/lab/convert-php-array-to-xml-with-attributes/
http://www.lalit.org/lab/convert-xml-to-array-in-php-xml2array/
http://www.lalit.org/lab/convert-php-array-to-xml-with-attributes/

## Changelog

Expand Down
71 changes: 40 additions & 31 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
{
"name": "openlss/lib-array2xml"
,"homepage": "https://www.nullivex.com"
,"description": "Array2XML conversion library credit to lalit.org"
,"license": "Apache-2.0"
,"type": "library"
,"keywords": [
"array"
,"xml"
,"xml conversion"
,"array conversion"
]
,"authors": [
{
"name": "Bryan Tong"
,"email": "[email protected]"
,"homepage": "https://www.nullivex.com"
}
,{
"name": "Tony Butler"
,"email": "[email protected]"
,"homepage": "https://www.nullivex.com"
}
]
,"require": {
"php": ">=5.3.2"
}
,"autoload": {
"psr-0": {
"LSS": ""
}
}
"name": "openlss/lib-array2xml",
"description": "Array2XML conversion library credit to lalit.org",
"type": "library",
"keywords": [
"array",
"array conversion",
"xml",
"xml conversion"
],
"homepage": "https://www.nullivex.com",
"license": "Apache-2.0",
"authors": [
{
"name": "Bryan Tong",
"email": "[email protected]",
"homepage": "https://www.nullivex.com"
},
{
"name": "Tony Butler",
"email": "[email protected]",
"homepage": "https://www.nullivex.com"
}
],
"require": {
"php": ">=5.3.2",
"ext-dom": "*"
},
"require-dev": {
"phpunit/phpunit": "~6.0 || ~7.0"
},
"autoload": {
"psr-4": {
"LSS\\": "LSS/"
}
},
"autoload-dev": {
"psr-4": {
"LSS_tests\\": "tests/"
}
}
}
21 changes: 21 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
verbose="true"
>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./LSS/</directory>
</whitelist>
</filter>
</phpunit>
36 changes: 36 additions & 0 deletions tests/Array2XMLTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace LSS_tests;

/**
* @internal
*/
final class Array2XMLTest extends \PHPUnit\Framework\TestCase
{
public function testCreateXml() {
$array = array(
'title' => 'A title',
'body' => array(
'@xml' => '<html><body><p>The content for the news item</p></body></html>',
),
);

// Use the Array2XML object to transform it.
$xml = \LSS\Array2XML::createXML('news', $array);

$expected = '<?xml version="1.0" encoding="UTF-8"?>
<news>
<title>A title</title>
<body>
<html>
<body>
<p>The content for the news item</p>
</body>
</html>
</body>
</news>
';

static::assertSame($expected, $xml->saveXML());
}
}
41 changes: 41 additions & 0 deletions tests/XML2ArrayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace LSS_tests;

/**
* @internal
*/
final class XML2ArrayTest extends \PHPUnit\Framework\TestCase
{
public function testCreateArray() {
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<news>
<title>A title</title>
<body>
<html>
<body>
<p>The content for the news item</p>
</body>
</html>
</body>
</news>
';

$array = \LSS\XML2Array::createArray($xml);

$expected = array(
'news' => array(
'title' => 'A title',
'body' => array(
'html' => array(
'body' => array(
'p' => 'The content for the news item',
),
),
),
),
);

static::assertSame($expected, $array);
}
}
6 changes: 6 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

\error_reporting(\E_ALL);
\ini_set('display_errors', 1);

require_once \dirname(__DIR__) . '/vendor/autoload.php';