PHPUnit : Fatal error handling

拥有回忆 提交于 2019-12-18 12:49:11

问题


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


回答1:


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).




回答2:


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



来源:https://stackoverflow.com/questions/3841190/phpunit-fatal-error-handling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!