mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Changing HtmlReporter to print out testname and stack trace instead of trying to guess where things went wrong.
This commit is contained in:
parent
4759b7adac
commit
71af126171
2 changed files with 24 additions and 22 deletions
|
@ -159,7 +159,7 @@ class CakeBaseReporter implements PHPUnit_Framework_TestListener {
|
||||||
* @param float $time
|
* @param float $time
|
||||||
*/
|
*/
|
||||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $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
|
* @param float $time
|
||||||
*/
|
*/
|
||||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
|
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
|
||||||
$this->paintFail($e);
|
$this->paintFail($e, $test);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -227,29 +227,16 @@ class CakeHtmlReporter extends CakeBaseReporter {
|
||||||
* the context of the other tests.
|
* the context of the other tests.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function paintFail($message) {
|
public function paintFail($message, $test) {
|
||||||
$context = $message->getTrace();
|
$trace = $this->_getStackTrace($message);
|
||||||
$realContext = $context[3];
|
$testName = get_class($test) . '(' . $test->getName() . ')';
|
||||||
$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];
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "<li class='fail'>\n";
|
echo "<li class='fail'>\n";
|
||||||
echo "<span>Failed</span>";
|
echo "<span>Failed</span>";
|
||||||
echo "<div class='msg'><pre>" . $this->_htmlEntities($message->toString()) . "</pre></div>\n";
|
echo "<div class='msg'><pre>" . $this->_htmlEntities($message->toString()) . "</pre></div>\n";
|
||||||
echo "<div class='msg'>" . sprintf(__('File: %s'), $context['file']) . "</div>\n";
|
|
||||||
echo "<div class='msg'>" . sprintf(__('Method: %s'), $realContext['function']) . "</div>\n";
|
echo "<div class='msg'>" . sprintf(__('Test case: %s'), $testName) . "</div>\n";
|
||||||
echo "<div class='msg'>" . sprintf(__('Line: %s'), $context['line']) . "</div>\n";
|
echo "<div class='msg'>" . __('Stack trace:') . '<br />' . $trace . "</div>\n";
|
||||||
echo "</li>\n";
|
echo "</li>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +265,7 @@ class CakeHtmlReporter extends CakeBaseReporter {
|
||||||
* @param Exception $exception Exception to display.
|
* @param Exception $exception Exception to display.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function paintException($exception) {
|
public function paintException($exception, $test) {
|
||||||
echo "<li class='fail'>\n";
|
echo "<li class='fail'>\n";
|
||||||
echo "<span>Exception</span>";
|
echo "<span>Exception</span>";
|
||||||
$message = 'Unexpected exception of type [' . get_class($exception) .
|
$message = 'Unexpected exception of type [' . get_class($exception) .
|
||||||
|
@ -323,6 +310,21 @@ class CakeHtmlReporter extends CakeBaseReporter {
|
||||||
return htmlentities($message, ENT_COMPAT, $this->_characterSet);
|
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('<br />', $out);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test suite started.
|
* A test suite started.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue