Description
Normalizes `Exception` objects and PHP error data into a single array format, and checks each error against the list of expected errors (set using `expectException()`). If a match is found, the expectation is removed from the stack and the error is ignored. If no match is found, then the error data is logged to the test results.
Parameters
- mixed $exception An `Exception` object instance, or an array containing the following keys: `'message'`, `'file'`, `'line'`, `'trace'` (in `debug_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
voidRelated
protected function _handleException($exception, $lineFlag = null) {
if (is_object($exception)) {
$data = array();
foreach (array('message', 'file', 'line', 'trace') as $key) {
$method = 'get' . ucfirst($key);
$data[$key] = $exception->{$method}();
}
$ref = $exception->getTrace();
$ref = $ref[0] + array('class' => null);
if ($ref['class'] == __CLASS__ && $ref['function'] == 'skipIf') {
return $this->_result('skip', $data);
}
$exception = $data;
}
$message = $exception['message'];
$isExpected = (($exp = end($this->_expected)) && ($exp === true || $exp == $message || (
Validator::isRegex($exp) && preg_match($exp, $message)
)));
if ($isExpected) {
return array_pop($this->_expected);
}
$this->_reportException($exception, $lineFlag);
}