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
|
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-06 01:44:01 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2010-01-06 01:44:01 +00:00
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) 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
|
|
|
* @since CakePHP(tm) v 1.3
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2010-01-06 01:44:01 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
2011-08-06 17:45:55 +00:00
|
|
|
App::uses('CakeBaseReporter', 'TestSuite/Reporter');
|
|
|
|
App::uses('TextCoverageReport', 'TestSuite/Coverage');
|
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
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.TestSuite.Reporter
|
2010-01-06 01:44:01 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function paintDocumentStart() {
|
2011-02-13 17:06:51 +00:00
|
|
|
if (!headers_sent()) {
|
2010-06-26 17:48:55 +00:00
|
|
|
header('Content-type: text/plain');
|
2011-02-13 17:06:51 +00:00
|
|
|
}
|
2010-05-13 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-26 17:48:55 +00:00
|
|
|
* Paints a pass
|
2010-05-13 04:18:22 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function paintPass() {
|
2010-06-26 17:48:55 +00:00
|
|
|
echo '.';
|
2010-05-13 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paints a failing test.
|
|
|
|
*
|
2012-11-28 22:30:47 +00:00
|
|
|
* @param PHPUnit_Framework_AssertionFailedError $message Failure object displayed in
|
2010-05-13 04:18:22 +00:00
|
|
|
* the context of the other tests.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function paintFail($message) {
|
|
|
|
$context = $message->getTrace();
|
|
|
|
$realContext = $context[3];
|
|
|
|
$context = $context[2];
|
|
|
|
|
|
|
|
printf(
|
2011-10-28 05:01:17 +00:00
|
|
|
"FAIL on line %s\n%s in\n%s %s()\n\n",
|
2010-05-13 04:18:22 +00:00
|
|
|
$context['line'], $message->toString(), $context['file'], $realContext['function']
|
|
|
|
);
|
2010-01-10 00:19:09 +00:00
|
|
|
}
|
|
|
|
|
2010-01-06 01:44:01 +00:00
|
|
|
/**
|
|
|
|
* Paints the end of the test with a summary of
|
|
|
|
* the passes and failures.
|
|
|
|
*
|
2010-05-13 04:18:22 +00:00
|
|
|
* @param PHPUnit_Framework_TestResult $result Result object
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2010-01-06 01:44:01 +00:00
|
|
|
*/
|
2010-05-13 04:18:22 +00:00
|
|
|
public function paintFooter($result) {
|
2012-09-14 17:42:25 +00:00
|
|
|
if ($result->failureCount() + $result->errorCount()) {
|
2010-01-06 01:44:01 +00:00
|
|
|
echo "FAILURES!!!\n";
|
2012-09-14 17:42:25 +00:00
|
|
|
} else {
|
|
|
|
echo "\nOK\n";
|
2010-01-06 01:44:01 +00:00
|
|
|
}
|
2009-10-31 07:30:59 +00:00
|
|
|
|
2011-10-28 05:01:17 +00:00
|
|
|
echo "Test cases run: " . $result->count() .
|
2010-05-13 04:18:22 +00:00
|
|
|
"/" . ($result->count() - $result->skippedCount()) .
|
|
|
|
', Passes: ' . $this->numAssertions .
|
|
|
|
', Failures: ' . $result->failureCount() .
|
|
|
|
', Exceptions: ' . $result->errorCount() . "\n";
|
|
|
|
|
2011-02-13 20:01:00 +00:00
|
|
|
echo 'Time: ' . $result->time() . " seconds\n";
|
2011-12-16 06:52:07 +00:00
|
|
|
echo 'Peak memory: ' . number_format(memory_get_peak_usage()) . " bytes\n";
|
2011-02-13 04:07:39 +00:00
|
|
|
|
2010-05-08 21:14:47 +00:00
|
|
|
if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
|
2011-08-06 17:45:55 +00:00
|
|
|
$coverage = $result->getCodeCoverage()->getSummary();
|
2010-05-08 21:14:47 +00:00
|
|
|
echo $this->paintCoverage($coverage);
|
2010-01-10 20:56:24 +00:00
|
|
|
}
|
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:56:25 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-05-13 04:18:22 +00:00
|
|
|
public function paintHeader() {
|
2010-01-10 18:05:35 +00:00
|
|
|
$this->paintDocumentStart();
|
2010-01-06 01:44:01 +00:00
|
|
|
flush();
|
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
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function paintException($exception) {
|
2010-01-06 01:44:01 +00:00
|
|
|
$message = 'Unexpected exception of type [' . get_class($exception) .
|
2012-03-05 02:51:44 +00:00
|
|
|
'] with message [' . $exception->getMessage() .
|
|
|
|
'] in [' . $exception->getFile() .
|
2010-06-26 17:02:35 +00:00
|
|
|
' line ' . $exception->getLine() . ']';
|
|
|
|
echo $message . "\n\n";
|
2010-01-06 01:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function paintSkip($message) {
|
2011-02-13 04:07:39 +00:00
|
|
|
printf("Skip: %s\n", $message->getMessage());
|
2010-01-06 01:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function paintFormattedMessage($message) {
|
2010-01-06 01:44:01 +00:00
|
|
|
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.
|
2013-10-08 03:17:58 +00:00
|
|
|
* Creates as series of URLs for tests that can be run.
|
2010-01-09 16:20:47 +00:00
|
|
|
* One case per line.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
public function testCaseList() {
|
2010-01-09 16:20:47 +00:00
|
|
|
$testCases = parent::testCaseList();
|
|
|
|
$app = $this->params['app'];
|
|
|
|
$plugin = $this->params['plugin'];
|
|
|
|
|
|
|
|
$buffer = "Core Test Cases:\n";
|
|
|
|
if ($app) {
|
|
|
|
$buffer = "App Test Cases:\n";
|
|
|
|
} elseif ($plugin) {
|
|
|
|
$buffer = Inflector::humanize($plugin) . " Test Cases:\n";
|
|
|
|
}
|
|
|
|
|
2013-09-06 16:36:57 +00:00
|
|
|
if (count($testCases) < 1) {
|
2013-06-09 15:20:08 +00:00
|
|
|
$buffer .= 'EMPTY';
|
2010-01-09 16:20:47 +00:00
|
|
|
echo $buffer;
|
|
|
|
}
|
|
|
|
|
2013-01-23 12:45:50 +00:00
|
|
|
foreach ($testCases as $testCase) {
|
2012-03-05 02:51:44 +00:00
|
|
|
$buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() . "?case=" . $testCase . "&output=text\n";
|
2010-01-09 16:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$buffer .= "\n";
|
|
|
|
echo $buffer;
|
|
|
|
}
|
2010-05-13 04:18:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a Text summary of the coverage data.
|
|
|
|
*
|
|
|
|
* @param array $coverage Array of coverage data.
|
2012-11-28 22:30:47 +00:00
|
|
|
* @return void
|
2010-05-13 04:18:22 +00:00
|
|
|
*/
|
|
|
|
public function paintCoverage($coverage) {
|
2010-05-14 01:36:23 +00:00
|
|
|
$reporter = new TextCoverageReport($coverage, $this);
|
|
|
|
echo $reporter->report();
|
2010-05-13 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 07:30:59 +00:00
|
|
|
}
|