mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Moving methods up into CakeBaseReporter.
Starting to make CakeTextReporter work well with PHPUnit so the Text code coverage reporting can be implemented.
This commit is contained in:
parent
d349551dd7
commit
17f338a9b2
3 changed files with 141 additions and 129 deletions
|
@ -26,7 +26,7 @@ PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
|
|||
* @package cake
|
||||
* @subpackage cake.tests.lib
|
||||
*/
|
||||
class CakeBaseReporter {
|
||||
class CakeBaseReporter implements PHPUnit_Framework_TestListener {
|
||||
|
||||
/**
|
||||
* Time the test runs started.
|
||||
|
@ -214,5 +214,88 @@ class CakeBaseReporter {
|
|||
return '';
|
||||
}
|
||||
|
||||
public function paintResult(PHPUnit_Framework_TestResult $result) {
|
||||
$this->paintFooter($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* An error occurred.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||
$this->paintException($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* A failure occurred.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param PHPUnit_Framework_AssertionFailedError $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
|
||||
$this->paintFail($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Incomplete test.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Skipped test.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A test suite started.
|
||||
*
|
||||
* @param PHPUnit_Framework_TestSuite $suite
|
||||
*/
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||
echo sprintf(__('Running %s'), $suite->getName()) . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* A test suite ended.
|
||||
*
|
||||
* @param PHPUnit_Framework_TestSuite $suite
|
||||
*/
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A test started.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
*/
|
||||
public function startTest(PHPUnit_Framework_Test $test) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A test ended.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param float $time
|
||||
*/
|
||||
public function endTest(PHPUnit_Framework_Test $test, $time) {
|
||||
$this->numAssertions += $test->getNumAssertions();
|
||||
$this->paintPass($test, $time);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -28,7 +28,7 @@ PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
|
|||
* @package cake
|
||||
* @subpackage cake.tests.lib
|
||||
*/
|
||||
class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_TestListener {
|
||||
class CakeHtmlReporter extends CakeBaseReporter {
|
||||
|
||||
/**
|
||||
* Paints the top of the web page setting the
|
||||
|
@ -152,7 +152,7 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes
|
|||
* Paints the end of the test with a summary of
|
||||
* the passes and failures.
|
||||
*
|
||||
* @param string $test_name Name class of test.
|
||||
* @param PHPUnit_Framework_TestResult $result Result object
|
||||
* @return void
|
||||
*/
|
||||
public function paintFooter($result) {
|
||||
|
@ -161,7 +161,7 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes
|
|||
echo "<div style=\"";
|
||||
echo "padding: 8px; margin: 1em 0; background-color: $colour; color: white;";
|
||||
echo "\">";
|
||||
echo $result->count() . "/" . $result->count() - $result->skippedCount();
|
||||
echo $result->count() . "/" . ($result->count() - $result->skippedCount());
|
||||
echo " test methods complete:\n";
|
||||
echo "<strong>" . count($result->passed()) . "</strong> passes, ";
|
||||
echo "<strong>" . $result->failureCount() . "</strong> fails, ";
|
||||
|
@ -272,9 +272,6 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes
|
|||
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(__('Line: %s'), $context['line']) . "</div>\n";
|
||||
//$breadcrumb = $this->getTestList();
|
||||
//array_shift($breadcrumb);
|
||||
//echo "<div>" . implode(" -> ", $breadcrumb) . "</div>\n";
|
||||
echo "</li>\n";
|
||||
}
|
||||
|
||||
|
@ -368,70 +365,6 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes
|
|||
return htmlentities($message, ENT_COMPAT, $this->_characterSet);
|
||||
}
|
||||
|
||||
public function paintResult(PHPUnit_Framework_TestResult $result) {
|
||||
|
||||
/*if ($result->errorCount() > 0) {
|
||||
$this->printErrors($result);
|
||||
}
|
||||
|
||||
if ($result->failureCount() > 0) {
|
||||
$this->printFailures($result);
|
||||
}
|
||||
|
||||
if ($result->skippedCount() > 0) {
|
||||
$this->printIncompletes($result);
|
||||
}
|
||||
|
||||
if ($result->skippedCount() > 0) {
|
||||
$this->printSkipped($result);
|
||||
}*/
|
||||
|
||||
$this->paintFooter($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* An error occurred.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||
$this->paintException($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* A failure occurred.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param PHPUnit_Framework_AssertionFailedError $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
|
||||
$this->paintFail($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Incomplete test.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Skipped test.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A test suite started.
|
||||
*
|
||||
|
@ -440,32 +373,5 @@ class CakeHtmlReporter extends CakeBaseReporter implements PHPUnit_Framework_Tes
|
|||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||
echo '<h2>' . sprintf(__('Running %s'), $suite->getName()) . '</h2>';
|
||||
}
|
||||
|
||||
/**
|
||||
* A test suite ended.
|
||||
*
|
||||
* @param PHPUnit_Framework_TestSuite $suite
|
||||
*/
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A test started.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
*/
|
||||
public function startTest(PHPUnit_Framework_Test $test) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A test ended.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param float $time
|
||||
*/
|
||||
public function endTest(PHPUnit_Framework_Test $test, $time) {
|
||||
$this->numAssertions += $test->getNumAssertions();
|
||||
$this->paintPass($test, $time);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -17,8 +17,11 @@
|
|||
* @since CakePHP(tm) v 1.3
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
|
||||
include_once dirname(__FILE__) . DS . 'cake_base_reporter.php';
|
||||
|
||||
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
|
||||
|
||||
/**
|
||||
* CakeTextReporter contains reporting features used for plain text based output
|
||||
*
|
||||
|
@ -33,31 +36,57 @@ class CakeTextReporter extends CakeBaseReporter {
|
|||
* @return void
|
||||
*/
|
||||
public function paintDocumentStart() {
|
||||
if (!SimpleReporter::inCli()) {
|
||||
header('Content-type: text/plain');
|
||||
}
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function paintPass() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints a failing test.
|
||||
*
|
||||
* @param $message PHPUnit_Framework_AssertionFailedError $message Failure object displayed in
|
||||
* the context of the other tests.
|
||||
* @return void
|
||||
*/
|
||||
public function paintFail($message) {
|
||||
$context = $message->getTrace();
|
||||
$realContext = $context[3];
|
||||
$context = $context[2];
|
||||
|
||||
printf(
|
||||
"FAIL on line %s\n%s in\n%s %s()\n\n",
|
||||
$context['line'], $message->toString(), $context['file'], $realContext['function']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints the end of the test with a summary of
|
||||
* the passes and failures.
|
||||
*
|
||||
* @param string $test_name Name class of test.
|
||||
* @param PHPUnit_Framework_TestResult $result Result object
|
||||
* @return void
|
||||
*/
|
||||
public function paintFooter($test_name) {
|
||||
if ($this->getFailCount() + $this->getExceptionCount() == 0) {
|
||||
public function paintFooter($result) {
|
||||
if ($result->failureCount() + $result->errorCount() == 0) {
|
||||
echo "OK\n";
|
||||
} else {
|
||||
echo "FAILURES!!!\n";
|
||||
}
|
||||
echo "Test cases run: " . $this->getTestCaseProgress() .
|
||||
"/" . $this->getTestCaseCount() .
|
||||
", Passes: " . $this->getPassCount() .
|
||||
", Failures: " . $this->getFailCount() .
|
||||
", Exceptions: " . $this->getExceptionCount() . "\n";
|
||||
|
||||
echo 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n";
|
||||
echo "Test cases run: " . $result->count() .
|
||||
"/" . ($result->count() - $result->skippedCount()) .
|
||||
', Passes: ' . $this->numAssertions .
|
||||
', Failures: ' . $result->failureCount() .
|
||||
', Exceptions: ' . $result->errorCount() . "\n";
|
||||
|
||||
echo 'Time taken by tests (in seconds): ' . $result->time() . "\n";
|
||||
if (function_exists('memory_get_peak_usage')) {
|
||||
echo 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n";
|
||||
}
|
||||
|
@ -73,28 +102,11 @@ class CakeTextReporter extends CakeBaseReporter {
|
|||
* @param string $test_name Name class of test.
|
||||
* @return void
|
||||
*/
|
||||
public function paintHeader($test_name) {
|
||||
public function paintHeader() {
|
||||
$this->paintDocumentStart();
|
||||
echo "$test_name\n";
|
||||
flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints the test failure as a stack trace.
|
||||
*
|
||||
* @param string $message Failure message displayed in
|
||||
* the context of the other tests.
|
||||
* @return void
|
||||
*/
|
||||
public function paintFail($message) {
|
||||
parent::paintFail($message);
|
||||
echo $this->getFailCount() . ") $message\n";
|
||||
$breadcrumb = $this->getTestList();
|
||||
array_shift($breadcrumb);
|
||||
echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints a PHP error.
|
||||
*
|
||||
|
@ -185,5 +197,16 @@ class CakeTextReporter extends CakeBaseReporter {
|
|||
$buffer .= "\n";
|
||||
echo $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a Text summary of the coverage data.
|
||||
*
|
||||
* @param array $coverage Array of coverage data.
|
||||
* @return string
|
||||
*/
|
||||
public function paintCoverage($coverage) {
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue