2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-01-10 01:19:49 +00:00
|
|
|
* Cake CLI test reporter.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2009-11-06 06:46:59 +00:00
|
|
|
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2008-10-30 17:30:26 +00:00
|
|
|
* @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
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-09-12 05:11:34 +00:00
|
|
|
if (version_compare(PHP_VERSION, '4.4.4', '<=') ||
|
|
|
|
PHP_SAPI == 'cgi') {
|
2008-06-20 20:17:23 +00:00
|
|
|
define('STDOUT', fopen('php://stdout', 'w'));
|
|
|
|
define('STDERR', fopen('php://stderr', 'w'));
|
|
|
|
register_shutdown_function(create_function('', 'fclose(STDOUT); fclose(STDERR); return true;'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-01-10 03:02:35 +00:00
|
|
|
include_once dirname(__FILE__) . DS . 'cake_base_reporter.php';
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2010-01-10 01:19:49 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.libs.reporter
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-01-10 03:02:35 +00:00
|
|
|
class CakeCliReporter extends CakeBaseReporter {
|
2010-01-10 04:00:03 +00:00
|
|
|
/**
|
|
|
|
* separator string for fail, error, exception, and skip messages.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-01-10 03:02:35 +00:00
|
|
|
var $separator = '->';
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-01-10 04:00:03 +00:00
|
|
|
/**
|
|
|
|
* array of 'request' parameters
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $params = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param string $separator
|
|
|
|
* @param array $params
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-01-10 20:55:49 +00:00
|
|
|
function CakeCLIReporter($charset = 'utf-8', $params = array()) {
|
|
|
|
$this->CakeBaseReporter($charset, $params);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setFailDetailSeparator($separator) {
|
2010-01-10 03:02:35 +00:00
|
|
|
$this->separator = $separator;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-10 03:02:35 +00:00
|
|
|
* Paint fail faildetail to STDERR.
|
|
|
|
*
|
|
|
|
* @param string $message Message of the fail.
|
|
|
|
* @return void
|
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-01-10 03:02:35 +00:00
|
|
|
function paintFail($message) {
|
|
|
|
parent::paintFail($message);
|
2010-01-10 03:51:17 +00:00
|
|
|
$message .= $this->_getBreadcrumb();
|
2010-01-10 03:02:35 +00:00
|
|
|
fwrite(STDERR, 'FAIL' . $this->separator . $message);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-10 03:02:35 +00:00
|
|
|
* Paint PHP errors to STDERR.
|
|
|
|
*
|
|
|
|
* @param string $message Message of the Error
|
|
|
|
* @return void
|
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-01-10 03:02:35 +00:00
|
|
|
function paintError($message) {
|
|
|
|
parent::paintError($message);
|
2010-01-10 03:51:17 +00:00
|
|
|
$message .= $this->_getBreadcrumb();
|
2010-01-10 03:02:35 +00:00
|
|
|
fwrite(STDERR, 'ERROR' . $this->separator . $message);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Paint exception faildetail to STDERR.
|
2010-01-10 03:02:35 +00:00
|
|
|
*
|
|
|
|
* @param string $message Message of the Error
|
|
|
|
* @return void
|
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-01-10 03:02:35 +00:00
|
|
|
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()
|
|
|
|
);
|
2010-01-10 03:51:17 +00:00
|
|
|
$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() {
|
2010-01-10 03:02:35 +00:00
|
|
|
$breadcrumb = $this->getTestList();
|
|
|
|
array_shift($breadcrumb);
|
2010-01-10 03:51:17 +00:00
|
|
|
$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");
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* 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";
|
2010-01-10 03:51:17 +00:00
|
|
|
$buffer .= $this->_timeStats();
|
2008-05-30 11:40:08 +00:00
|
|
|
fwrite(STDOUT, $buffer);
|
|
|
|
} else {
|
2010-01-10 03:51:17 +00:00
|
|
|
fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n" . $this->_timeStats());
|
|
|
|
}
|
2010-01-11 23:04:08 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
isset($this->params['codeCoverage']) &&
|
|
|
|
$this->params['codeCoverage'] &&
|
|
|
|
class_exists('CodeCoverageManager')
|
|
|
|
) {
|
|
|
|
CodeCoverageManager::report();
|
|
|
|
}
|
2010-01-10 03:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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";
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-01-10 03:51:17 +00:00
|
|
|
return $out;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|