Assume I have want to assert if these XML snipplets are the same:
public function assertXmlIsSame() {
$leExpectedXml = <<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$leActualXml = <<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder
</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$this->assertEquals(
$leExpectedXml,
$leActualXml,
'le xmls should be the same'
);
}
I get the output:
Fail Failed asserting that two strings are equal. ( -Expected | +Actual )
- '<note>
- <to>Tove</to>
- <from>Jani</from>
- <heading>Reminder</heading>
- <body>Don't forget me this weekend!</body>
- </note>'
+ '<note>
+ <to>Tove</to>
+ <from>Jani</from>
+ <heading>Reminder
+ </heading>
+ <body>Don't forget me this weekend!</body>
+ </note>'
which is not helpful, as the whole XML is dumped even with equals line.
If I create a SebastianBergmann\Diff\Differ
and dump that diff:
$diff = (new Differ())->diff($leExpectedXml, $leActualXml);
codecept_debug($diff);
The output looks like this:
--- Original
+++ New
@@ @@
<note>
<to>Tove</to>
<from>Jani</from>
- <heading>Reminder</heading>
+ <heading>Reminder
+ </heading>
<body>Don't forget me this weekend!</body>
</note>
Much more readable and more what I was expecting from codeception.
Is there for codeception only to hightlight the diff for changed parts? As esp. if the xml structures become larger, it's almost impossible to see the difference with the default codeception diff output.