Skip to content
Permalink
Browse files

Adding output levels to Shell

Adding tests for output levels.
  • Loading branch information...
markstory committed Oct 14, 2010
1 parent c6ef589 commit 4be57a2ea5fdd4ef99fba61d70b6962fde7360bd
Showing with 49 additions and 3 deletions.
  1. +19 −2 cake/console/libs/shell.php
  2. +30 −1 cake/tests/cases/console/libs/shell.test.php
@@ -29,6 +29,13 @@
*/
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 @@ protected function _getInput($prompt, $options, $default) {
* @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;
}
/**
@@ -259,7 +259,36 @@ public function testOut() {
* @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);
}
/**

0 comments on commit 4be57a2

Please sign in to comment.
You can’t perform that action at this time.