class PHPUnit_Util_ErrorHandler in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/phpunit/phpunit/src/Util/ErrorHandler.php \PHPUnit_Util_ErrorHandler
Error handler that converts PHP errors and warnings to exceptions.
@since Class available since Release 3.3.0
Hierarchy
- class \PHPUnit_Util_ErrorHandler
Expanded class hierarchy of PHPUnit_Util_ErrorHandler
1 string reference to 'PHPUnit_Util_ErrorHandler'
- PHPUnit_Framework_TestResult::run in vendor/
phpunit/ phpunit/ src/ Framework/ TestResult.php - Runs a TestCase.
File
- vendor/
phpunit/ phpunit/ src/ Util/ ErrorHandler.php, line 24
View source
class PHPUnit_Util_ErrorHandler {
protected static $errorStack = array();
/**
* Returns the error stack.
*
* @return array
*/
public static function getErrorStack() {
return self::$errorStack;
}
/**
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @throws PHPUnit_Framework_Error
*/
public static function handleError($errno, $errstr, $errfile, $errline) {
if (!($errno & error_reporting())) {
return false;
}
self::$errorStack[] = array(
$errno,
$errstr,
$errfile,
$errline,
);
$trace = debug_backtrace(false);
array_shift($trace);
foreach ($trace as $frame) {
if ($frame['function'] == '__toString') {
return false;
}
}
if ($errno == E_NOTICE || $errno == E_USER_NOTICE || $errno == E_STRICT) {
if (PHPUnit_Framework_Error_Notice::$enabled !== true) {
return false;
}
$exception = 'PHPUnit_Framework_Error_Notice';
}
elseif ($errno == E_WARNING || $errno == E_USER_WARNING) {
if (PHPUnit_Framework_Error_Warning::$enabled !== true) {
return false;
}
$exception = 'PHPUnit_Framework_Error_Warning';
}
elseif ($errno == E_DEPRECATED || $errno == E_USER_DEPRECATED) {
if (PHPUnit_Framework_Error_Deprecated::$enabled !== true) {
return false;
}
$exception = 'PHPUnit_Framework_Error_Deprecated';
}
else {
$exception = 'PHPUnit_Framework_Error';
}
throw new $exception($errstr, $errno, $errfile, $errline);
}
/**
* Registers an error handler and returns a function that will restore
* the previous handler when invoked
* @param int $severity PHP predefined error constant
* @throws Exception if event of specified severity is emitted
*/
public static function handleErrorOnce($severity = E_WARNING) {
$terminator = function () {
static $expired = false;
if (!$expired) {
$expired = true;
// cleans temporary error handler
return restore_error_handler();
}
};
set_error_handler(function ($errno, $errstr) use ($severity) {
if ($errno === $severity) {
return;
}
return false;
});
return $terminator;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PHPUnit_Util_ErrorHandler:: |
protected static | property | ||
PHPUnit_Util_ErrorHandler:: |
public static | function | Returns the error stack. | |
PHPUnit_Util_ErrorHandler:: |
public static | function | ||
PHPUnit_Util_ErrorHandler:: |
public static | function | Registers an error handler and returns a function that will restore the previous handler when invoked |