クラスPHPUnit_Framework_TestcaseでメソッドassertEquals()を使用して比較すると、次のようになります。
_NULL_に対する_false_、
_false_に対する_emptystring_、
_NULL_に対する_emptystring_
すべてのテストに合格しました。 しかし、互いに等しい値はありません。 したがって、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()
があります。