PHPUnit - 断言两个字符串是相同的,它们是

时间:2010-11-09 15:27:54

标签: phpunit selenium-rc

我正在使用带有PHPunit的selenium RC,我遇到了这个问题。我正在尝试做assertEqual,但这是结果:

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 abc
 def

步骤线:

$this->assertEquals("abc\ndef", $this->getValue("text"));

和“text”是“abc \ ndef”。

在Firefox中,它运行正常。问题只出在IE上。结果他没告诉我什么是不平等的。

2 个答案:

答案 0 :(得分:4)

最有可能是回车(\r),其中没有显示PHPUnit的字符串差异输出。使用addslashes()serialize()显示隐藏的字符。

$this->assertEquals(addslashes("abc\ndef"), addslashes($this->getValue("text")));

答案 1 :(得分:2)

我为与Google一起到达此处的人们添加了答案 你也可以这样做:

$this->assertEquals(preg_split('/\r\n|\r|\n/', "abc\ndef"), preg_split('/\r\n|\r|\n/', $this->getValue("text")));

// Note the return line in the PHP file without any space at the begining
$this->assertEquals(preg_split('/\r\n|\r|\n/', 'abc
def'), preg_split('/\r\n|\r|\n/', $this->getValue("text")));
相关问题