【发布时间】:2014-09-26 16:01:06
【问题描述】:
我正在尝试使用我的规范捕获异常,但我无法使其正常工作。这是我的代码:
$this->edit('updated comment', $comment, $user)
->shouldReturnAnInstanceOf('\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException');
我做错了什么?
【问题讨论】:
我正在尝试使用我的规范捕获异常,但我无法使其正常工作。这是我的代码:
$this->edit('updated comment', $comment, $user)
->shouldReturnAnInstanceOf('\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException');
我做错了什么?
【问题讨论】:
根据documentation,您可以使用Matcher 执行类似的操作来测试异常:
$this
->shouldThrow('Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException')
->during('edit', array('updated comment', $comment, $user));
您还可以查看cookbook,它位于 Github 上的 phpspec 存储库中。
【讨论】: