2014-09-26 76 views
1

我试图捕捉异常与我的规范,但我不能使它的作品。这是我的代码:如何用phpspec2捕捉异常

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

我在做什么错了?

回答

3

documentation,可以用于测试异常做这样的事情使用Matcher

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

您还可以看看到cookbook这是在Github上phpspec库。