Difference between assertEquals and assertSame in PHPUnit?

后端 未结 7 1166
别那么骄傲
别那么骄傲 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:34

    assertSame() == Tests that if the actual output and the expected parameter are same.

    that is :

    $this->assertSame('$expected','$expected');
    

    or

    $this->assertSame('100','100');
    

    assertEquals == If we see with respect to a website page, i have a page which has 2 'table' so when i run assertEquals i will check its count that the 'table' are 2 by using a count function. Eg:

    $this->assertEquals(2, $var->filter('table')->count()); 
    

    Here we can see that assertEquals checks that there are 2 tables found on the web page. we can also use divisions found on the page using '#division name' inside the bracket.

    Eg 2:

    public function testAdd()
    {
        $calc = new Calculator();
    
        $result = $calc->add(30, 12);
    
        // assert that our calculator added the numbers correctly!
        $this->assertEquals(42, $result);
    }
    

提交回复
热议问题