Can I make PHPUnit fail if the code throws a notice?

帅比萌擦擦* 提交于 2019-12-13 14:28:30

问题


It doesn't appear to do it by default, and I don't see any switch for it either.

This is PHPUnit 2.3.5, and PHP 5.2.0-8.


回答1:


You want to upgrade to a more recent version of PHPUnit, have a look at http://www.phpunit.de/.




回答2:


function exception_error_handler($errno, $errstr, $errfile, $errline ) 
{
    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");



回答3:


Your available option appears to be using set_error_handler() to override the error process (PHPUnit installs its own, which you'd be replacing). Then you'd either duplicate what PHPUnit's error handler does, except triggering failure on E_NOTICEs, or hand off to PHPUnit's error handler (which you'll get a handle to returned from set_error_handler()) and fake up E_NOTICES as something more critical.



来源:https://stackoverflow.com/questions/679854/can-i-make-phpunit-fail-if-the-code-throws-a-notice

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