Difference between assertEquals and assertSame in PHPUnit?

后端 未结 7 1145
别那么骄傲
别那么骄傲 2021-01-30 18:54

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

相关标签:
7条回答
  • 2021-01-30 19:59

    As it's been said before,AssertSame reports an error if the two elements do not share type and value but it's also important to note this from the docummentation:

    Reports an error identified by $message if the two variables $expected and $actual do not reference the same object.

    So this test would fail too even though they share type and value:

    class SameTest extends TestCase
    {
        public function testFailure()
        {
            $this->assertSame(new stdClass, new stdClass);
        }
    }
    
    0 讨论(0)
提交回复
热议问题