How to compare similar XMLs with PHPUnit?

php, phpunit, zend-framework

Solution

This seems to have solved the problem:

https://phpunit.de/manual/current/en/appendixes.assertions.html#appendixes.assertions.assertXmlStringEqualsXmlString

Problem

So let's say I want to compare two DOMDocument objects. They have the same content but order and formatting might be off. For example, first one outputs this XML: ``` <responses> <response id="12"> <foo>bar</foo> <lorem>ipsum</lorem> <sit>dolor</sit> </response></responses> ``` Other one outputs: ``` <responses> <response id="12"> <lorem>ipsum</lorem><sit>dolor</sit> <foo>bar</foo> </response> </responses> ``` As you can see, they contain the same XML structure but some elements might be in different order and formatting is completely random. If I do: ``` $this->assertEquals(); ``` The test will of course fail. I don't want to test just XML structure but also contents. Any ideas?

Original source

Related problems