lithium\test\Unit::_handleException()
Normalizes Exception
objects and PHP error data into a single array format
then the error data is logged to the test results.
Parameters
-
mixed
$exception
An
Exception
object instance, or an array containing the following keys:'name'
,'message'
,'file'
,'line'
,'trace'
(indebug_backtrace()
format) and optionally'code'
(error code number) and'context'
(an array of variables relevant to the scope of where the error occurred). -
integer
$lineFlag
A flag used for determining the relevant scope of the call stack. Set to the line number where test methods are called.
Returns
voidSource
protected function _handleException($exception, $lineFlag = null) {
$data = $exception;
if (is_object($exception)) {
$data = ['name' => get_class($exception)];
foreach (['message', 'file', 'line', 'trace', 'code'] as $key) {
$method = 'get' . ucfirst($key);
$data[$key] = $exception->{$method}();
}
if ($exception instanceof ErrorException) {
$mapSeverity = function($severity) {
foreach (get_defined_constants(true)['Core'] as $constant => $value) {
if (substr($constant, 0, 2) === 'E_' && $value === $severity) {
return $constant;
}
}
return 'E_UNKNOWN';
};
$data['code'] = $mapSeverity($exception->getSeverity());
}
$ref = $exception->getTrace();
$ref = $ref[0] + ['class' => null];
if ($ref['class'] === __CLASS__ && $ref['function'] === 'skipIf') {
return $this->_result('skip', $data);
}
}
return $this->_reportException($data, $lineFlag);
}