Skip to content

Commit 79d1739

Browse files
committed
Adding tests for task methods in runCommand.
Moving startup() call to the dispatcher so nested runCommand calls don't double output the startup content.
1 parent cea9dad commit 79d1739

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

cake/console/libs/shell.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ public function hasMethod($name) {
329329
* @return void
330330
*/
331331
public function runCommand($command, $argv) {
332-
$this->startup();
333332
if (!empty($command) && $this->hasTask($command)) {
333+
$command = Inflector::camelize($command);
334334
return $this->{$command}->runCommand('execute', $argv);
335335
}
336336

cake/console/shell_dispatcher.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ public function dispatch() {
269269
if ($Shell instanceof Shell) {
270270
$Shell->initialize();
271271
$Shell->loadTasks();
272+
$Shell->startup();
272273
return $Shell->runCommand($command, $this->args);
273274
}
274275
$methods = array_diff(get_class_methods($Shell), get_class_methods('Shell'));

cake/tests/cases/console/libs/shell.test.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ function testRunCommandMain() {
613613
$Mock = $this->getMock('Shell', array('main', 'startup'), array(), '', false);
614614

615615
$Mock->expects($this->once())->method('main')->will($this->returnValue(true));
616-
$Mock->expects($this->once())->method('startup');
617616
$result = $Mock->runCommand(null, array());
618617
$this->assertTrue($result);
619618
}
@@ -628,7 +627,6 @@ function testRunCommandBaseclassMethod() {
628627
$methods = get_class_methods('Shell');
629628
$Mock = $this->getMock('Shell', array('startup'), array(), '', false);
630629

631-
$Mock->expects($this->once())->method('startup');
632630
$Mock->expects($this->never())->method('hr');
633631
$result = $Mock->runCommand('hr', array());
634632
}
@@ -638,7 +636,7 @@ function testRunCommandBaseclassMethod() {
638636
*
639637
* @return void
640638
*/
641-
function testHelpParamTriggeringHelp() {
639+
function testRunCommandTriggeringHelp() {
642640
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
643641
$Parser->expects($this->once())->method('parse')
644642
->with(array('--help'))
@@ -649,8 +647,22 @@ function testHelpParamTriggeringHelp() {
649647
$Shell->expects($this->once())->method('_getOptionParser')
650648
->will($this->returnValue($Parser));
651649
$Shell->expects($this->once())->method('out');
652-
$Shell->expects($this->once())->method('startup');
653650

654651
$Shell->runCommand(null, array('--help'));
655652
}
653+
654+
/**
655+
* test that runCommand will call runCommand on the task.
656+
*
657+
* @return void
658+
*/
659+
function testRunCommandHittingTask() {
660+
$Shell = $this->getMock('Shell', array('hasTask'), array(), '', false);
661+
$task = $this->getMock('Shell', array('execute'), array(), '', false);
662+
$Shell->tasks = array('RunCommand');
663+
$Shell->expects($this->once())->method('hasTask')->will($this->returnValue(true));
664+
$Shell->RunCommand = $task;
665+
666+
$Shell->runCommand('run_command', array());
667+
}
656668
}

0 commit comments

Comments
 (0)