PHPUnit: assertInstanceOf() not working

后端 未结 3 1206
感动是毒
感动是毒 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:42

    It's always a good idea to use ::class wherever you can. If you get used to this standard, you don't have to use FQCNs (fully qualified classnames), or escape backslashes. Also, IDEs provide better functionality if they know that User here is not just a string, but rather a class.

    $this->assertInstanceOf(User::class, $user);
    

提交回复
热议问题