开发者

PHPUnit - assert that two strings are equal and they are

开发者 https://www.devze.com 2023-01-24 18:42 出处:网络
I\'m using selenium RC with 开发者_Go百科PHPunit and i have this problem. I\'m trying to do assertEqual but this is the result:

I'm using selenium RC with 开发者_Go百科PHPunit and i have this problem. I'm trying to do assertEqual but this is the result:

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

The step line:

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

and "text" is "abc\ndef".

In firefox it's working ok. The problem is only with IE. In the result he doesn't tell me what is not equal..


There's most likely a carriage return (\r) in there which PHPUnit's string diff output isn't displaying. Use addslashes() or serialize() to display the hidden characters.

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


I add an answer for the people that arrive here with Google.
You can do like that too:

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

or

// 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")));
0

精彩评论

暂无评论...
验证码 换一张
取 消