PHPUnit-断言两个字符串相等,并且

PHPUnit-断言两个字符串相等,并且,phpunit,selenium-rc,Phpunit,Selenium Rc,我将selenium RC与PHPunit一起使用,我遇到了这个问题。我试图做assertEqual,但结果是: Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ abc def 步骤行: $this->assertEquals("abc\ndef", $this->getValue("text")); “文本”是“abc\ndef” 在firefox中工作正常。问题只出现在I

我将selenium RC与PHPunit一起使用,我遇到了这个问题。我试图做assertEqual,但结果是:

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 abc
 def
步骤行:

$this->assertEquals("abc\ndef", $this->getValue("text"));
“文本”是“abc\ndef”


在firefox中工作正常。问题只出现在IE上。结果中,他没有告诉我什么是不相等的。

很可能有一个回车(
\r
)在那里,PHPUnit的字符串差异输出没有显示出来。使用
addslashes()
serialize()
显示隐藏字符

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

我为那些通过谷歌来到这里的人添加了一个答案。
你也可以这样做:

$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")));