1

我试图用我的规范捕捉异常,但我不能让它工作。这是我的代码:

$this->edit('updated comment', $comment, $user)
    ->shouldReturnAnInstanceOf('\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException');

我做错了什么?

4

1 回答 1

3

根据文档,您可以使用Matcher测试异常来执行以下操作:

$this
   ->shouldThrow('Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException')
   ->during('edit', array('updated comment', $comment, $user));

您还可以查看Github 上phpspec存储库中的说明书。

于 2014-09-26T16:58:07.797 回答