Difference between assertEquals and assertSame in PHPUnit?

I use both sporadically, but according to the docs:

assertSame

Reports an error identified by $message if the two variables $expected and $actual do not have the same type and value.”

And as you can see in the example below the above excerpt, they are passing '2204' and 2204, which will fail using assertSame because one is a string and one is an int, basically:

'2204' !== 2204
assertSame('2204', 2204) // this test fails

assertEquals

“Reports an error identified by $message if the two variables $expected and $actual are not equal.”

assertEquals does not appear to take datatype into consideration so using the above example of 2204:

'2204' == 2204
assertEquals('2204', 2204) // this test passes

I just ran some unit tests against the above examples, and indeed they resulted in documented behavior.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)