PHPUnit:致命错误处理

发布于 2024-09-26 05:15:33 字数 259 浏览 2 评论 0原文

我使用 PHPUnit 进行单元测试,但是当触发致命错误时,脚本死亡并且我没有正确的 PHPUnit 输出。

我希望 PHPUnit 输出保持格式正确,因为它是由 Eclipse 插件读取的。实际上,致命错误会停止 PHPUnit,并且在 Eclipse 中插件无法解释任何内容(因为 PHPUnit 脚本错误,而不是处理它)。

谢谢

I use PHPUnit for unit tests, but when a fatal error is triggered, the script dies and I have no correct PHPUnit output.

I'd like that the PHPUnit output stays correctly formated, because it is read by a plugin for Eclipse. Actually the fatal error stops PHPUnit and in Eclipse the plugin can't interpret anything (because the PHPUnit script had an error, instead of handling it).

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

渔村楼浪 2024-10-03 05:15:33

您需要使用 PHPUnit 的进程隔离功能 - 在新进程中启动每个测试套件。

phpunit --process-isolation ...

这是确保致命错误不会破坏 phpunit 输出的唯一方法。

执行时间

进程隔离会成倍增加您的测试运行时间,因为对于每个测试,都会启动一个新的 PHP 实例,执行引导程序等。

要修改这种情况,您可以选择在一个单独的进程 (@runTestsInSeparateProcesses),或仅已知有时会致命的单个进程 (@runInSeparateProcess)。

You need to use PHPUnit's process isolation features - start each test suite in a new process.

phpunit --process-isolation ...

This is the only way to make sure fatal errors don't break your phpunit output.

Execution time

Process isolation multiplies your test run time, because for each single test, a new PHP instance is started, the bootstrap is executed etc.

To amend this situation, you may choose to run full test cases in a separate process (@runTestsInSeparateProcesses), or only single ones that are known to fatal out sometimes (@runInSeparateProcess).

冰雪梦之恋 2024-10-03 05:15:33

set_error_handler() 不会帮助你。您可以使用 register_shutdown_function() 捕获致命错误

set_error_handler() won't help you there. You can catch fatal errors using register_shutdown_function()

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