我有这个代码:
public function method(){
//...
if(!$exist) {
throw new \InvalidArgumentException('Ce client inexistant', 400);
}
}
我做这段代码的UT:
public function methodTest(){
//...
if(!$exist) {
$this->expectExceptionMessage("Ce client inexistant");
$this->expectException("\InvalidArgumentException");
}
}
它显示错误消息
无法断言抛出类型“\ InvalidArgumentException”的异常。
我不知道我的代码中的错误在哪里。
尝试
$this->expectException(\InvalidArgumentException::class);
代替:
$this->expectException("\InvalidArgumentException");
希望这有帮助
我解决了我的问题。这是代码:
$ this-> throwException(new \ InvalidArgumentException('Ce client inexistant',400));