使用 PHPUnit 检测任何 PHP 错误/警告/异常
我希望 PHPUnit 在遇到任何 PHP 错误、警告或异常时失败。
我看到了相反的例子,
/**
* @expectedException PHPUnit_Framework_Error_Warning
*/
当预计会出现错误时使用 where 。但相反,我想练习各种代码路径并保证不会引发错误、警告或异常。
I'd like to have PHPUnit fail when it encounters any PHP error, warning, or exception.
I'm seeing examples of the inverse, where
/**
* @expectedException PHPUnit_Framework_Error_Warning
*/
is used when an error is expected. But instead, I'd like to exercise various code paths and guarantee that no errors, warnings, or exceptions were thrown.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
任何引发未捕获的异常或引发警告或错误的测试都会由 PHPUnit 自动标记为
E
(表示错误),而无需您的干预。当您想将此类错误计为正确行为时,您只需采取类似@expectedException
的措施即可。Any test that throws an uncaught exception or raises a warning or error is automatically marked with
E
(for error) by PHPUnit without your intervention. You only need to take measures like@expectedException
when you want to count such errors as correct behavior.