当我在类 PHPUnit_Framework_Testcase 中使用方法 assertEquals() 并进行比较时:
_false_ 反对 _NULL_,
_空字符串_反对_false_,
_空字符串_反对_NULL_
所有测试都成功通过。 但是没有任何值是相等的。 所以 assertEquals 与“==”运算符进行比较,而不是“===”或类似的东西。 认为它应该是这样的。 但为什么?
我们有assertSame()
用于===
比较。
好吧完美。 这些名字有点误导。 但这是我的错。 对不起。
但是assertSame()
只会比较true
,如果对象相同。
class Foo {}
$this->assertSame(new Foo(), new Foo());
Failed asserting that two variables reference the same object.
我需要一些可以像这样工作的代码:
$this->assertSame(new Foo(null), new Foo("")); // false
$this->assertSame(new Foo(null), new Foo(null)); // true
$this->assertSame(new Foo(""), new Foo("")); // true
最有用的评论
我们有
assertSame()
用于===
比较。