使用 PHPUnit 检测任何 PHP 错误/警告/异常

发布于 2024-12-21 15:22:57 字数 206 浏览 3 评论 0原文

我希望 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七色彩虹 2024-12-28 15:22:57

任何引发未捕获的异常或引发警告或错误的测试都会由 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文