Adding output levels to Shell

Adding tests for output levels.
This commit is contained in:
mark_story 2010-10-13 23:40:45 -04:00
parent c6ef589139
commit 4be57a2ea5
2 changed files with 49 additions and 3 deletions

View file

@ -29,6 +29,13 @@ require_once CAKE . 'console' . DS . 'console_input.php';
*/
class Shell extends Object {
/**
* Output constants for making verbose and quiet shells.
*/
const VERBOSE = 2;
const NORMAL = 1;
const QUIET = 0;
/**
* An instance of the ShellDispatcher object that loaded this script
*
@ -448,8 +455,18 @@ class Shell extends Object {
* @param integer $newlines Number of newlines to append
* @return integer Returns the number of bytes returned from writing to stdout.
*/
public function out($message = null, $newlines = 1) {
return $this->stdout->write($message, $newlines);
public function out($message = null, $newlines = 1, $level = Shell::NORMAL) {
$currentLevel = Shell::NORMAL;
if (!empty($this->params['verbose'])) {
$currentLevel = Shell::VERBOSE;
}
if (!empty($this->params['quiet'])) {
$currentLevel = Shell::QUIET;
}
if ($level <= $currentLevel) {
return $this->stdout->write($message, $newlines);
}
return true;
}
/**

View file

@ -259,7 +259,36 @@ class ShellTest extends CakeTestCase {
* @return void
*/
function testVerboseOutput() {
$this->markTestIncomplete('This needs to be written.');
$this->Shell->stdout->expects($this->at(0))->method('write')
->with('Verbose', 1);
$this->Shell->stdout->expects($this->at(1))->method('write')
->with('Normal', 1);
$this->Shell->stdout->expects($this->at(2))->method('write')
->with('Quiet', 1);
$this->Shell->params['verbose'] = true;
$this->Shell->params['quiet'] = false;
$this->Shell->out('Verbose', 1, Shell::VERBOSE);
$this->Shell->out('Normal', 1, Shell::NORMAL);
$this->Shell->out('Quiet', 1, Shell::QUIET);
}
/**
* test that verbose and quiet output levels work
*
* @return void
*/
function testQuietOutput() {
$this->Shell->stdout->expects($this->once())->method('write')
->with('Quiet', 1);
$this->Shell->params['verbose'] = false;
$this->Shell->params['quiet'] = true;
$this->Shell->out('Verbose', 1, Shell::VERBOSE);
$this->Shell->out('Normal', 1, Shell::NORMAL);
$this->Shell->out('Quiet', 1, Shell::QUIET);
}
/**