PHPUnit 7:无法断言抛出\ InvalidArgumentException类型的异常

fatma_wings

我有以下代码:

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”的异常失败。

我不知道我的代码中的错误在哪里。

fatma_wings

我解决了我的问题。这是代码:

$ this-> throwException(new \ InvalidArgumentException('Ce client inexistant',400));

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章