PHPUnit: assertInstanceOf() not working

后端 未结 3 1098
感动是毒
感动是毒 2021-02-02 05:13

I need to check if a variable is an object of the User type. User is my class $user my object

$this->assertInstanceOf($user,User);
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 05:45

    Or You can use something like:

    $this->assertInstanceOf(get_class($expectedObject), $user);
    

    I usually use this when I'm checking i.e. if setter method is returning reference to self.

    $testedObj = new ObjectToTest();
    $this->assertInstanceOf(
        get_class($testedObj), 
        $testedObj->setSomething('someValue'),
        'Setter is not returning $this reference'
    );
    

提交回复
热议问题