mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding output levels to Shell
Adding tests for output levels.
This commit is contained in:
parent
c6ef589139
commit
4be57a2ea5
2 changed files with 49 additions and 3 deletions
|
@ -29,6 +29,13 @@ require_once CAKE . 'console' . DS . 'console_input.php';
|
||||||
*/
|
*/
|
||||||
class Shell extends Object {
|
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
|
* 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
|
* @param integer $newlines Number of newlines to append
|
||||||
* @return integer Returns the number of bytes returned from writing to stdout.
|
* @return integer Returns the number of bytes returned from writing to stdout.
|
||||||
*/
|
*/
|
||||||
public function out($message = null, $newlines = 1) {
|
public function out($message = null, $newlines = 1, $level = Shell::NORMAL) {
|
||||||
return $this->stdout->write($message, $newlines);
|
$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 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testVerboseOutput() {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue