diff --git a/cake/tests/lib/reporter/cake_base_reporter.php b/cake/tests/lib/reporter/cake_base_reporter.php index c7d7a7648..7f1eea9d7 100644 --- a/cake/tests/lib/reporter/cake_base_reporter.php +++ b/cake/tests/lib/reporter/cake_base_reporter.php @@ -159,7 +159,7 @@ class CakeBaseReporter implements PHPUnit_Framework_TestListener { * @param float $time */ public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) { - $this->paintException($e); + $this->paintException($e, $test); } /** @@ -170,7 +170,7 @@ class CakeBaseReporter implements PHPUnit_Framework_TestListener { * @param float $time */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { - $this->paintFail($e); + $this->paintFail($e, $test); } /** diff --git a/cake/tests/lib/reporter/cake_html_reporter.php b/cake/tests/lib/reporter/cake_html_reporter.php index 27a482a87..e8c51e69e 100755 --- a/cake/tests/lib/reporter/cake_html_reporter.php +++ b/cake/tests/lib/reporter/cake_html_reporter.php @@ -227,29 +227,16 @@ class CakeHtmlReporter extends CakeBaseReporter { * the context of the other tests. * @return void */ - public function paintFail($message) { - $context = $message->getTrace(); - $realContext = $context[3]; - $class = new ReflectionClass($realContext['class']); - - $deeper = false; - if ($class->getParentClass()) { - $deeper = $class->getParentClass()->getName() === 'PHPUnit_Framework_TestCase'; - } - $deeper = $deeper || !$class->isSubclassOf('PHPUnit_Framework_TestCase'); - if ($deeper) { - $realContext = $context[4]; - $context = $context[3]; - } else { - $context = $context[2]; - } + public function paintFail($message, $test) { + $trace = $this->_getStackTrace($message); + $testName = get_class($test) . '(' . $test->getName() . ')'; echo "
  • \n"; echo "Failed"; echo "
    " . $this->_htmlEntities($message->toString()) . "
    \n"; - echo "
    " . sprintf(__('File: %s'), $context['file']) . "
    \n"; - echo "
    " . sprintf(__('Method: %s'), $realContext['function']) . "
    \n"; - echo "
    " . sprintf(__('Line: %s'), $context['line']) . "
    \n"; + + echo "
    " . sprintf(__('Test case: %s'), $testName) . "
    \n"; + echo "
    " . __('Stack trace:') . '
    ' . $trace . "
    \n"; echo "
  • \n"; } @@ -278,7 +265,7 @@ class CakeHtmlReporter extends CakeBaseReporter { * @param Exception $exception Exception to display. * @return void */ - public function paintException($exception) { + public function paintException($exception, $test) { echo "
  • \n"; echo "Exception"; $message = 'Unexpected exception of type [' . get_class($exception) . @@ -323,6 +310,21 @@ class CakeHtmlReporter extends CakeBaseReporter { return htmlentities($message, ENT_COMPAT, $this->_characterSet); } +/** + * Gets a formatted stack trace. + * + * @param Exception $e Exception to get a stack trace for. + * @return string Generated stack trace. + */ + protected function _getStackTrace(Exception $e) { + $trace = $e->getTrace(); + $out = array(); + foreach ($trace as $frame) { + $out[] = $frame['file'] . ' : ' . $frame['line']; + } + return implode('
    ', $out); + } + /** * A test suite started. *