Skip to content

Commit

Permalink
Making CakeCliReporter a subclass of CakeBaseReporter.
Browse files Browse the repository at this point in the history
Removing duplicated output from reporter message.
Adjusting formatting of output to be more readable.
  • Loading branch information
markstory committed Jan 10, 2010
1 parent 081509a commit 7b5adde
Showing 1 changed file with 49 additions and 21 deletions.
70 changes: 49 additions & 21 deletions cake/tests/lib/reporter/cake_cli_reporter.php
Expand Up @@ -24,54 +24,82 @@
register_shutdown_function(create_function('', 'fclose(STDOUT); fclose(STDERR); return true;')); 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 * 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. * to the shell if all tests pass, ST_FAILS_RETURN_CODE if any test fails.
* *
* @package cake * @package cake
* @subpackage cake.tests.libs.reporter * @subpackage cake.tests.libs.reporter
*/ */
class CakeCliReporter extends TextReporter { class CakeCliReporter extends CakeBaseReporter {


var $faildetail_separator = '->'; var $separator = '->';


function CakeCLIReporter($faildetail_separator = NULL) { function CakeCLIReporter($separator = NULL) {
$this->SimpleReporter(); $this->SimpleReporter();
if (! is_null($faildetail_separator)) { if (!is_null($separator)) {
$this->setFailDetailSeparator($faildetail_separator); $this->setFailDetailSeparator($separator);
} }
} }


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


/** /**
* Return a formatted faildetail for printing. * Paint fail faildetail to STDERR.
*
* @param string $message Message of the fail.
* @return void
* @access public
*/ */
function &_paintTestFailDetail(&$message) { function paintFail($message) {
$buffer = ''; parent::paintFail($message);
$faildetail = $this->getTestList(); $breadcrumb = $this->getTestList();
array_shift($faildetail); array_shift($breadcrumb);
$buffer .= implode($this->faildetail_separator, $faildetail); $message .= "\n\tin " . implode("\n\tin ", array_reverse($breadcrumb));
$buffer .= $this->faildetail_separator . "$message\n"; $message .= "\n\n";
return $buffer; fwrite(STDERR, 'FAIL' . $this->separator . $message);
} }


/** /**
* Paint fail faildetail to STDERR. * Paint PHP errors to STDERR.
*
* @param string $message Message of the Error
* @return void
* @access public
*/ */
function paintFail($message) { function paintError($message) {
parent::paintFail($message); parent::paintError($message);
fwrite(STDERR, 'FAIL' . $this->faildetail_separator . $this->_paintTestFailDetail($message)); $breadcrumb = $this->getTestList();
array_shift($breadcrumb);
$message .= "\n\tin " . implode("\n\tin ", array_reverse($breadcrumb));
$message .= "\n\n";
fwrite(STDERR, 'ERROR' . $this->separator . $message);
} }


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


/** /**
Expand Down

0 comments on commit 7b5adde

Please sign in to comment.