PHPUnit contains an assertEquals() method, but it also has an assertSame() one. At first glance it looks like they do the same thing.
What is the difference between the t
As previously mentioned, assertEquals()
is primarily about an interpreted value, be it by type juggling or an object with an __magic presentation method (__toString()
for example).
A good use case for assertSame()
is testing a singleton factory.
class CacheFactoryTest extends TestCase
{
public function testThatCacheFactoryReturnsSingletons()
{
$this->assertSame(CacheFactory::create(), CacheFactory::create());
}
}