public function printExceptionTrace(\Exception $e) { static $limit = 10; $class = $e instanceof \PHPUnit_Framework_ExceptionWrapper ? $e->getClassname() : get_class($e); if ($this->rawStackTrace) { $this->message(\PHPUnit_Util_Filter::getFilteredStacktrace($e, true, false))->writeln(); return; } $trace = \PHPUnit_Util_Filter::getFilteredStacktrace($e, false); $i = 0; foreach ($trace as $step) { if ($i >= $limit) { break; } $i++; $message = $this->message($i)->prepend('#')->width(4); if (!isset($step['file'])) { foreach (['class', 'type', 'function'] as $info) { if (!isset($step[$info])) { continue; } $message->append($step[$info]); } $message->writeln(); continue; } $message->append($step['file'] . ':' . $step['line']); $message->writeln(); } $prev = $e->getPrevious(); if ($prev) { $this->printExceptionTrace($prev); } }
/** * Returns a description for an exception. * * @param Exception $e * @return string * @since Method available since Release 3.2.0 */ public static function exceptionToString(Exception $e) { if ($e instanceof PHPUnit_Framework_SelfDescribing) { $buffer = $e->toString(); if ($e instanceof PHPUnit_Framework_ExpectationFailedException && $e->getComparisonFailure()) { $buffer = $buffer . $e->getComparisonFailure()->getDiff(); } if (!empty($buffer)) { $buffer = trim($buffer) . "\n"; } } elseif ($e instanceof PHPUnit_Framework_Error) { $buffer = $e->getMessage() . "\n"; } elseif ($e instanceof PHPUnit_Framework_ExceptionWrapper) { $buffer = $e->getClassname() . ': ' . $e->getMessage() . "\n"; } else { $buffer = get_class($e) . ': ' . $e->getMessage() . "\n"; } return $buffer; }
public function printException(\Exception $e) { static $limit = 10; $class = $e instanceof \PHPUnit_Framework_ExceptionWrapper ? $e->getClassname() : get_class($e); $this->message("[%s] %s")->with($class, $e->getMessage())->block('error')->writeln($e instanceof \PHPUnit_Framework_AssertionFailedError ? OutputInterface::VERBOSITY_DEBUG : OutputInterface::VERBOSITY_VERBOSE); if ($this->rawStackTrace) { $this->message($e->getTraceAsString())->writeln(); return; } $trace = \PHPUnit_Util_Filter::getFilteredStacktrace($e, false); $i = 0; foreach ($trace as $step) { if ($i >= $limit) { break; } $i++; $message = $this->message($i)->prepend('#')->width(4); if (!isset($step['file'])) { foreach (['class', 'type', 'function'] as $info) { if (!isset($step[$info])) { continue; } $message->append($step[$info]); } $message->writeln(); continue; } $message->append($step['file'] . ':' . $step['line']); $message->writeln(); } $prev = $e->getPrevious(); if ($prev) { $this->printException($prev); } }