Open TravisCarden opened 3 years ago
The XML writer doesn't work on XML that contains attributes. I discovered this trying to modify my phpunit.xml.
phpunit.xml
Here's a passing test case with one of the project's own mocks:
$raw = <<<RAW <?xml version="1.0" encoding="UTF-8"?> <config> <application> <name>configuration</name> <secret>s3cr3t</secret> </application> <host>localhost</host> <port>80</port> <servers> <server1>host1</server1> <server2>host2</server2> <server3>host3</server3> </servers> </config> RAW; $config = new \Noodlehaus\Config($raw, new \Noodlehaus\Parser\Xml(), TRUE); $xml = $config->toString(new \Noodlehaus\Writer\Xml(), TRUE); print $xml;
Result:
<?xml version="1.0"?> <config> <application> <name>configuration</name> <secret>s3cr3t</secret> </application> <host>localhost</host> <port>80</port> <servers> <server1>host1</server1> <server2>host2</server2> <server3>host3</server3> </servers> </config>
Add an attribute to any element in the XML, and it will fail:
$raw = <<<RAW <?xml version="1.0" encoding="UTF-8"?> <config test="example"> <application> <name>configuration</name> <secret>s3cr3t</secret> </application> <host>localhost</host> <port>80</port> <servers> <server1>host1</server1> <server2>host2</server2> <server3>host3</server3> </servers> </config> RAW; $config = new \Noodlehaus\Config($raw, new \Noodlehaus\Parser\Xml(), TRUE); $xml = $config->toString(new \Noodlehaus\Writer\Xml(), TRUE); var_dump($xml);
<?xml version="1.0"?>
Hi, @TravisCarden. Thanks for opening this issue! I'll work on a fix.
The XML writer doesn't work on XML that contains attributes. I discovered this trying to modify my
phpunit.xml
.Here's a passing test case with one of the project's own mocks:
Result:
Add an attribute to any element in the XML, and it will fail:
Result: