Skip to content
Permalink
Browse files

Buffer contents of HtmlReporter.

Collect HTML output into a buffer so we can provide compatibility across
PHPUnit 3.x and 4.x

Refs #11588
  • Loading branch information...
markstory committed Dec 31, 2017
1 parent 51206d7 commit d2c4bf2bb2eb4f4ff6c715d221f2e485e4f05112
Showing with 21 additions and 4 deletions.
  1. +21 −4 lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php
@@ -25,6 +25,13 @@
*/
class CakeHtmlReporter extends CakeBaseReporter {
/**
* The content buffer
*
* @var string
*/
protected $_buffer = '';
/**
* Paints the top of the web page setting the
* title to the name of the starting test.
@@ -33,12 +40,13 @@ class CakeHtmlReporter extends CakeBaseReporter {
*/
public function paintHeader() {
$this->_headerSent = true;
ob_start();
$this->sendContentType();
$this->sendNoCacheHeaders();
$this->paintDocumentStart();
$this->paintTestMenu();
echo "<ul class='tests'>\n";
ob_end_flush();
$this->_buffer = ob_get_clean();
}
/**
@@ -58,7 +66,6 @@ public function sendContentType() {
* @return void
*/
public function paintDocumentStart() {
ob_start();
$baseDir = $this->params['baseDir'];
include CAKE . 'TestSuite' . DS . 'templates' . DS . 'header.php';
}
@@ -135,7 +142,9 @@ public function sendNoCacheHeaders() {
* @return void
*/
public function paintFooter($result) {
echo $this->_buffer;
ob_end_flush();
$colour = ($result->failureCount() + $result->errorCount() > 0 ? "red" : "green");
echo "</ul>\n";
echo "<div style=\"";
@@ -248,6 +257,7 @@ public function paintDocumentEnd() {
* @return void
*/
public function paintFail($message, $test) {
ob_start();
$trace = $this->_getStackTrace($message);
$className = get_class($test);
$testName = $className . '::' . $test->getName() . '()';
@@ -286,6 +296,7 @@ public function paintFail($message, $test) {
}
echo "<div class='msg'>" . __d('cake_dev', 'Stack trace:') . '<br />' . $trace . "</div>\n";
echo "</li>\n";
$this->_buffer .= ob_get_clean();
}
/**
@@ -298,13 +309,15 @@ public function paintFail($message, $test) {
* @return void
*/
public function paintPass(PHPUnit_Framework_Test $test, $time = null) {
ob_start();
if (isset($this->params['showPasses']) && $this->params['showPasses']) {
echo "<li class='pass'>\n";
echo "<span>Passed</span> ";
echo "<br />" . $this->_htmlEntities($test->getName()) . " ($time seconds)\n";
echo "</li>\n";
}
$this->_buffer .= ob_get_clean();
}
/**
@@ -315,6 +328,7 @@ public function paintPass(PHPUnit_Framework_Test $test, $time = null) {
* @return void
*/
public function paintException($message, $test) {
ob_start();
$trace = $this->_getStackTrace($message);
$testName = get_class($test) . '(' . $test->getName() . ')';
@@ -325,6 +339,7 @@ public function paintException($message, $test) {
echo "<div class='msg'>" . __d('cake_dev', 'Test case: %s', $testName) . "</div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Stack trace:') . '<br />' . $trace . "</div>\n";
echo "</li>\n";
$this->_buffer .= ob_get_clean();
}
/**
@@ -335,10 +350,12 @@ public function paintException($message, $test) {
* @return void
*/
public function paintSkip($message, $test) {
ob_start();
echo "<li class='skipped'>\n";
echo "<span>Skipped</span> ";
echo $test->getName() . ': ' . $this->_htmlEntities($message->getMessage());
echo "</li>\n";
$this->_buffer .= ob_get_clean();
}
/**
@@ -390,9 +407,9 @@ protected function _getStackTrace(Exception $e) {
*/
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
if (!$this->_headerSent) {
echo $this->paintHeader();
$this->paintHeader();
}
echo '<h2>' . __d('cake_dev', 'Running %s', $suite->getName()) . '</h2>';
$this->_buffer .= '<h2>' . __d('cake_dev', 'Running %s', $suite->getName()) . '</h2>';
}
/**

0 comments on commit d2c4bf2

Please sign in to comment.
You can’t perform that action at this time.