Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 178 lines (164 sloc) 4.815 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
<?php
/**
* Cake CLI test reporter.
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* 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)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package cake
* @subpackage cake.cake.tests.libs
* @since CakePHP(tm) v 1.2.0.4433
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
if (version_compare(PHP_VERSION, '4.4.4', '<=') ||
PHP_SAPI == 'cgi') {
define('STDOUT', fopen('php://stdout', 'w'));
define('STDERR', fopen('php://stderr', 'w'));
register_shutdown_function(create_function('', 'fclose(STDOUT); fclose(STDERR); return true;'));
}

include_once dirname(__FILE__) . DS . 'cake_base_reporter.php';

/**
* Minimal command line test displayer. Writes fail details to STDERR. Returns 0
* to the shell if all tests pass, ST_FAILS_RETURN_CODE if any test fails.
*
* @package cake
* @subpackage cake.tests.libs.reporter
*/
class CakeCliReporter extends CakeBaseReporter {
/**
* separator string for fail, error, exception, and skip messages.
*
* @var string
*/
var $separator = '->';

/**
* array of 'request' parameters
*
* @var array
*/
var $params = array();

/**
* Constructor
*
* @param string $separator
* @param array $params
* @return void
*/
function CakeCLIReporter($charset = 'utf-8', $params = array()) {
$this->CakeBaseReporter($charset, $params);
}

function setFailDetailSeparator($separator) {
$this->separator = $separator;
}

/**
* Paint fail faildetail to STDERR.
*
* @param string $message Message of the fail.
* @return void
* @access public
*/
function paintFail($message) {
parent::paintFail($message);
$message .= $this->_getBreadcrumb();
fwrite(STDERR, 'FAIL' . $this->separator . $message);
}

/**
* Paint PHP errors to STDERR.
*
* @param string $message Message of the Error
* @return void
* @access public
*/
function paintError($message) {
parent::paintError($message);
$message .= $this->_getBreadcrumb();
fwrite(STDERR, 'ERROR' . $this->separator . $message);
}

/**
* Paint exception faildetail to STDERR.
*
* @param string $message Message of the Error
* @return void
* @access public
*/
function paintException($exception) {
parent::paintException($exception);
$message = sprintf('Unexpected exception of type [%s] with message [%s] in [%s] line [%s]',
get_class($exception),
$exception->getMessage(),
$exception->getFile(),
$exception->getLine()
);
$message .= $this->_getBreadcrumb();
fwrite(STDERR, 'EXCEPTION' . $this->separator . $message);
}

/**
* Get the breadcrumb trail for the current test method/case
*
* @return string The string for the breadcrumb
*/
function _getBreadcrumb() {
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);
$out = "\n\tin " . implode("\n\tin ", array_reverse($breadcrumb));
$out .= "\n\n";
return $out;
}

/**
* Paint a test skip message
*
* @param string $message The message of the skip
* @return void
*/
function paintSkip($message) {
parent::paintSkip($message);
fwrite(STDOUT, 'SKIP' . $this->separator . $message . "\n\n");
}

/**
* Paint a footer with test case name, timestamp, counts of fails and exceptions.
*/
function paintFooter($test_name) {
$buffer = $this->getTestCaseProgress() . '/' . $this->getTestCaseCount() . ' test cases complete: ';

if (0 < ($this->getFailCount() + $this->getExceptionCount())) {
$buffer .= $this->getPassCount() . " passes";
if (0 < $this->getFailCount()) {
$buffer .= ", " . $this->getFailCount() . " fails";
}
if (0 < $this->getExceptionCount()) {
$buffer .= ", " . $this->getExceptionCount() . " exceptions";
}
$buffer .= ".\n";
$buffer .= $this->_timeStats();
fwrite(STDOUT, $buffer);
} else {
fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n" . $this->_timeStats());
}

if (
isset($this->params['codeCoverage']) &&
$this->params['codeCoverage'] &&
class_exists('CodeCoverageManager')
) {
CodeCoverageManager::report();
}
}

/**
* Get the time and memory stats for this test case/group
*
* @return string String content to display
* @access protected
*/
function _timeStats() {
$out = 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n";
if (function_exists('memory_get_peak_usage')) {
$out .= 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n";
}
return $out;
}
}
Something went wrong with that request. Please try again.