dtkvlj5386 2016-06-16 11:37
浏览 46

如何获得更可读的diff for asseception assertEequals string?

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向