Phpunit: assertEquals(): NULL, true and empty string are the same

Created on 15 Sep 2013  ·  3Comments  ·  Source: sebastianbergmann/phpunit

When I use method assertEquals() in class PHPUnit_Framework_Testcase and compare:

_false_ against _NULL_,
_empty string_ against _false_,
_empty string_ against _NULL_

All the tests pass sucessfully. But no value is equal to each other. So assertEquals compares with "==" operator instead of "===" or something like that. Think it's supposed to be as it is. But why?

Most helpful comment

We have assertSame() for === comparisons.

All 3 comments

We have assertSame() for === comparisons.

Okay perfect. The names are a bit missleading. But it's my fault. Sorry for that.

But assertSame() will only compare true, if the objects are the same.

class Foo {}
$this->assertSame(new Foo(), new Foo());
Failed asserting that two variables reference the same object.

I need some code that can works like this:

$this->assertSame(new Foo(null), new Foo("")); // false

$this->assertSame(new Foo(null), new Foo(null)); // true
$this->assertSame(new Foo(""), new Foo("")); // true
Was this page helpful?
0 / 5 - 0 ratings

Related issues

stephen-leavitt-sonyatv-com picture stephen-leavitt-sonyatv-com  ·  4Comments

dciancu picture dciancu  ·  3Comments

kunjalpopat picture kunjalpopat  ·  4Comments

greg0ire picture greg0ire  ·  4Comments

ezzatron picture ezzatron  ·  3Comments