Created
February 24, 2015 09:49
-
-
Save blockjon/fb3682acfc9db76ae8f7 to your computer and use it in GitHub Desktop.
register_shutdown_function() handler we use with PHPUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
register_shutdown_function(function() { | |
$error = error_get_last(); | |
if( $error !== NULL) { | |
$errno = $error["type"]; | |
$errfile = $error["file"]; | |
$errline = $error["line"]; | |
$errstr = $error["message"]; | |
// only log fatal-type errors; all other errors will be handled by set_error_handler() above. | |
if (!($errno & E_USER_ERROR || $errno & E_COMPILE_ERROR || $errno & E_PARSE || $errno & E_ERROR)) { | |
return; | |
} | |
if(inPhpunit()) { | |
echo "\nFatal PHP error encountered: \n"; | |
print_r($error); | |
$testFile = 'unknown'; | |
$testName = 'unknown'; | |
$testClass = 'unknown'; | |
if (isset($GLOBALS['phpunit_last_test_name'])) { | |
$testName = $GLOBALS['phpunit_last_test_name']; | |
} | |
if (isset($GLOBALS['phpunit_last_test_file'])) { | |
$testFile = $GLOBALS['phpunit_last_test_file']; | |
} | |
if (isset($GLOBALS['phpunit_last_test_class'])) { | |
$testClass = $GLOBALS['phpunit_last_test_class']; | |
} | |
echo "Test File: $testFile\n"; | |
echo "Test Class: $testClass\n"; | |
echo "Test Name: $testName\n"; | |
echo "memory_limit = " . ini_get("memory_limit") . "\n"; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment