From d2c4bf2bb2eb4f4ff6c715d221f2e485e4f05112 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 30 Dec 2017 23:37:10 -0500 Subject: [PATCH] Buffer contents of HtmlReporter. Collect HTML output into a buffer so we can provide compatibility across PHPUnit 3.x and 4.x Refs #11588 --- .../TestSuite/Reporter/CakeHtmlReporter.php | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php b/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php index f73bb1927..f77c6f37b 100644 --- a/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php +++ b/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php @@ -25,6 +25,13 @@ App::uses('CakeBaseReporter', 'TestSuite/Reporter'); */ 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 "\n"; echo "
_getStackTrace($message); $className = get_class($test); $testName = $className . '::' . $test->getName() . '()'; @@ -286,6 +296,7 @@ class CakeHtmlReporter extends CakeBaseReporter { } echo "
" . __d('cake_dev', 'Stack trace:') . '
' . $trace . "
\n"; echo "\n"; + $this->_buffer .= ob_get_clean(); } /** @@ -298,6 +309,7 @@ class CakeHtmlReporter extends CakeBaseReporter { * @return void */ public function paintPass(PHPUnit_Framework_Test $test, $time = null) { + ob_start(); if (isset($this->params['showPasses']) && $this->params['showPasses']) { echo "
  • \n"; echo "Passed "; @@ -305,6 +317,7 @@ class CakeHtmlReporter extends CakeBaseReporter { echo "
    " . $this->_htmlEntities($test->getName()) . " ($time seconds)\n"; echo "
  • \n"; } + $this->_buffer .= ob_get_clean(); } /** @@ -315,6 +328,7 @@ class CakeHtmlReporter extends CakeBaseReporter { * @return void */ public function paintException($message, $test) { + ob_start(); $trace = $this->_getStackTrace($message); $testName = get_class($test) . '(' . $test->getName() . ')'; @@ -325,6 +339,7 @@ class CakeHtmlReporter extends CakeBaseReporter { echo "
    " . __d('cake_dev', 'Test case: %s', $testName) . "
    \n"; echo "
    " . __d('cake_dev', 'Stack trace:') . '
    ' . $trace . "
    \n"; echo "\n"; + $this->_buffer .= ob_get_clean(); } /** @@ -335,10 +350,12 @@ class CakeHtmlReporter extends CakeBaseReporter { * @return void */ public function paintSkip($message, $test) { + ob_start(); echo "
  • \n"; echo "Skipped "; echo $test->getName() . ': ' . $this->_htmlEntities($message->getMessage()); echo "
  • \n"; + $this->_buffer .= ob_get_clean(); } /** @@ -390,9 +407,9 @@ class CakeHtmlReporter extends CakeBaseReporter { */ public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { if (!$this->_headerSent) { - echo $this->paintHeader(); + $this->paintHeader(); } - echo '

    ' . __d('cake_dev', 'Running %s', $suite->getName()) . '

    '; + $this->_buffer .= '

    ' . __d('cake_dev', 'Running %s', $suite->getName()) . '

    '; } /**