2009-10-31 07:30:59 +00:00
|
|
|
<?php
|
2010-01-06 01:44:01 +00:00
|
|
|
/**
|
|
|
|
* CakeTextReporter contains reporting features used for plain text based output
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
|
|
|
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:03:03 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-01-06 01:44:01 +00:00
|
|
|
* @package cake
|
2010-01-10 00:37:37 +00:00
|
|
|
* @subpackage cake.tests.libs.reporter
|
2010-01-06 01:44:01 +00:00
|
|
|
* @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';
|
2009-10-31 07:30:59 +00:00
|
|
|
|
2010-01-06 01:44:01 +00:00
|
|
|
/**
|
|
|
|
* CakeTextReporter contains reporting features used for plain text based output
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.lib
|
|
|
|
*/
|
|
|
|
class CakeTextReporter extends CakeBaseReporter {
|
2010-01-09 16:20:47 +00:00
|
|
|
|
2010-01-10 00:19:09 +00:00
|
|
|
/**
|
|
|
|
* Sets the text/plain header if the test is not a CLI test.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function paintDocumentStart() {
|
|
|
|
if (!SimpleReporter::inCli()) {
|
|
|
|
header('Content-type: text/plain');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-06 01:44:01 +00:00
|
|
|
/**
|
|
|
|
* Paints the end of the test with a summary of
|
|
|
|
* the passes and failures.
|
|
|
|
*
|
|
|
|
* @param string $test_name Name class of test.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2010-01-06 01:44:01 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function paintFooter($test_name) {
|
|
|
|
if ($this->getFailCount() + $this->getExceptionCount() == 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";
|
2009-10-31 07:30:59 +00:00
|
|
|
|
2010-01-06 01:44:01 +00:00
|
|
|
echo 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n";
|
|
|
|
if (function_exists('memory_get_peak_usage')) {
|
|
|
|
echo 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n";
|
|
|
|
}
|
2010-01-10 20:56:24 +00:00
|
|
|
if (
|
|
|
|
isset($this->params['codeCoverage']) &&
|
|
|
|
$this->params['codeCoverage'] &&
|
|
|
|
class_exists('CodeCoverageManager')
|
|
|
|
) {
|
|
|
|
CodeCoverageManager::report();
|
|
|
|
}
|
2010-01-06 01:44:01 +00:00
|
|
|
}
|
2010-01-10 00:19:09 +00:00
|
|
|
|
2009-10-31 07:30:59 +00:00
|
|
|
/**
|
2010-01-06 01:44:01 +00:00
|
|
|
* Paints the title only.
|
2009-10-31 07:30:59 +00:00
|
|
|
*
|
2010-01-06 01:44:01 +00:00
|
|
|
* @param string $test_name Name class of test.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2010-01-06 01:44:01 +00:00
|
|
|
* @access public
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-01-06 01:44:01 +00:00
|
|
|
function paintHeader($test_name) {
|
2010-01-10 18:05:35 +00:00
|
|
|
$this->paintDocumentStart();
|
2010-01-06 01:44:01 +00:00
|
|
|
echo "$test_name\n";
|
|
|
|
flush();
|
2009-10-31 07:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-01-06 01:44:01 +00:00
|
|
|
* Paints the test failure as a stack trace.
|
2009-10-31 07:30:59 +00:00
|
|
|
*
|
2010-01-06 01:44:01 +00:00
|
|
|
* @param string $message Failure message displayed in
|
|
|
|
* the context of the other tests.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2010-01-06 01:44:01 +00:00
|
|
|
* @access public
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-01-06 01:44:01 +00:00
|
|
|
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";
|
2009-10-31 07:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-01-06 01:44:01 +00:00
|
|
|
* Paints a PHP error.
|
2009-10-31 07:30:59 +00:00
|
|
|
*
|
2010-01-06 01:44:01 +00:00
|
|
|
* @param string $message Message to be shown.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2010-01-06 01:44:01 +00:00
|
|
|
* @access public
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-01-06 01:44:01 +00:00
|
|
|
function paintError($message) {
|
|
|
|
parent::paintError($message);
|
|
|
|
echo "Exception " . $this->getExceptionCount() . "!\n$message\n";
|
|
|
|
$breadcrumb = $this->getTestList();
|
|
|
|
array_shift($breadcrumb);
|
|
|
|
echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
|
|
|
|
echo "\n";
|
2009-10-31 07:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-01-06 01:44:01 +00:00
|
|
|
* Paints a PHP exception.
|
2009-10-31 07:30:59 +00:00
|
|
|
*
|
2010-01-06 01:44:01 +00:00
|
|
|
* @param Exception $exception Exception to describe.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2009-10-31 07:30:59 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2010-01-06 01:44:01 +00:00
|
|
|
function paintException($exception) {
|
|
|
|
parent::paintException($exception);
|
|
|
|
$message = 'Unexpected exception of type [' . get_class($exception) .
|
|
|
|
'] with message ['. $exception->getMessage() .
|
|
|
|
'] in ['. $exception->getFile() .
|
|
|
|
' line ' . $exception->getLine() . ']';
|
|
|
|
echo "Exception " . $this->getExceptionCount() . "!\n$message\n";
|
|
|
|
$breadcrumb = $this->getTestList();
|
|
|
|
array_shift($breadcrumb);
|
|
|
|
echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
|
|
|
|
echo "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prints the message for skipping tests.
|
|
|
|
*
|
|
|
|
* @param string $message Text of skip condition.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2010-01-06 01:44:01 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function paintSkip($message) {
|
|
|
|
parent::paintSkip($message);
|
|
|
|
echo "Skip: $message\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paints formatted text such as dumped variables.
|
|
|
|
*
|
|
|
|
* @param string $message Text to show.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2010-01-06 01:44:01 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function paintFormattedMessage($message) {
|
|
|
|
echo "$message\n";
|
|
|
|
flush();
|
2009-10-31 07:30:59 +00:00
|
|
|
}
|
2010-01-09 16:20:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a test case list in plain text.
|
|
|
|
* Creates as series of url's for tests that can be run.
|
|
|
|
* One case per line.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testCaseList() {
|
|
|
|
$testCases = parent::testCaseList();
|
|
|
|
$app = $this->params['app'];
|
|
|
|
$plugin = $this->params['plugin'];
|
|
|
|
|
|
|
|
$buffer = "Core Test Cases:\n";
|
|
|
|
$urlExtra = '';
|
|
|
|
if ($app) {
|
|
|
|
$buffer = "App Test Cases:\n";
|
|
|
|
$urlExtra = '&app=true';
|
|
|
|
} elseif ($plugin) {
|
|
|
|
$buffer = Inflector::humanize($plugin) . " Test Cases:\n";
|
|
|
|
$urlExtra = '&plugin=' . $plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1 > count($testCases)) {
|
|
|
|
$buffer .= "EMPTY";
|
|
|
|
echo $buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($testCases as $testCaseFile => $testCase) {
|
|
|
|
$buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() ."?case=" . $testCase . "&output=text"."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$buffer .= "\n";
|
|
|
|
echo $buffer;
|
|
|
|
}
|
2009-10-31 07:30:59 +00:00
|
|
|
}
|
|
|
|
?>
|