Skip to content

Commit

Permalink
Adding tests for task methods in runCommand.
Browse files Browse the repository at this point in the history
Moving startup() call to the dispatcher so nested runCommand calls don't double output the startup content.
  • Loading branch information
markstory committed Oct 14, 2010
1 parent cea9dad commit 79d1739
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cake/console/libs/shell.php
Expand Up @@ -329,8 +329,8 @@ public function hasMethod($name) {
* @return void
*/
public function runCommand($command, $argv) {
$this->startup();
if (!empty($command) && $this->hasTask($command)) {
$command = Inflector::camelize($command);
return $this->{$command}->runCommand('execute', $argv);
}

Expand Down
1 change: 1 addition & 0 deletions cake/console/shell_dispatcher.php
Expand Up @@ -269,6 +269,7 @@ public function dispatch() {
if ($Shell instanceof Shell) {
$Shell->initialize();
$Shell->loadTasks();
$Shell->startup();
return $Shell->runCommand($command, $this->args);
}
$methods = array_diff(get_class_methods($Shell), get_class_methods('Shell'));
Expand Down
20 changes: 16 additions & 4 deletions cake/tests/cases/console/libs/shell.test.php
Expand Up @@ -613,7 +613,6 @@ function testRunCommandMain() {
$Mock = $this->getMock('Shell', array('main', 'startup'), array(), '', false);

$Mock->expects($this->once())->method('main')->will($this->returnValue(true));
$Mock->expects($this->once())->method('startup');
$result = $Mock->runCommand(null, array());
$this->assertTrue($result);
}
Expand All @@ -628,7 +627,6 @@ function testRunCommandBaseclassMethod() {
$methods = get_class_methods('Shell');
$Mock = $this->getMock('Shell', array('startup'), array(), '', false);

$Mock->expects($this->once())->method('startup');
$Mock->expects($this->never())->method('hr');
$result = $Mock->runCommand('hr', array());
}
Expand All @@ -638,7 +636,7 @@ function testRunCommandBaseclassMethod() {
*
* @return void
*/
function testHelpParamTriggeringHelp() {
function testRunCommandTriggeringHelp() {
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
$Parser->expects($this->once())->method('parse')
->with(array('--help'))
Expand All @@ -649,8 +647,22 @@ function testHelpParamTriggeringHelp() {
$Shell->expects($this->once())->method('_getOptionParser')
->will($this->returnValue($Parser));
$Shell->expects($this->once())->method('out');
$Shell->expects($this->once())->method('startup');

$Shell->runCommand(null, array('--help'));
}

/**
* test that runCommand will call runCommand on the task.
*
* @return void
*/
function testRunCommandHittingTask() {
$Shell = $this->getMock('Shell', array('hasTask'), array(), '', false);
$task = $this->getMock('Shell', array('execute'), array(), '', false);
$Shell->tasks = array('RunCommand');
$Shell->expects($this->once())->method('hasTask')->will($this->returnValue(true));
$Shell->RunCommand = $task;

$Shell->runCommand('run_command', array());
}
}

0 comments on commit 79d1739

Please sign in to comment.