diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index 7daabc081..3b9fe1304 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -329,8 +329,8 @@ class Shell extends Object { * @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); } diff --git a/cake/console/shell_dispatcher.php b/cake/console/shell_dispatcher.php index 338278748..a7616a5d1 100644 --- a/cake/console/shell_dispatcher.php +++ b/cake/console/shell_dispatcher.php @@ -269,6 +269,7 @@ class ShellDispatcher { 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')); diff --git a/cake/tests/cases/console/libs/shell.test.php b/cake/tests/cases/console/libs/shell.test.php index 45a25075a..f57650d6e 100644 --- a/cake/tests/cases/console/libs/shell.test.php +++ b/cake/tests/cases/console/libs/shell.test.php @@ -613,7 +613,6 @@ class ShellTest extends CakeTestCase { $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); } @@ -628,7 +627,6 @@ class ShellTest extends CakeTestCase { $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()); } @@ -638,7 +636,7 @@ class ShellTest extends CakeTestCase { * * @return void */ - function testHelpParamTriggeringHelp() { + function testRunCommandTriggeringHelp() { $Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false); $Parser->expects($this->once())->method('parse') ->with(array('--help')) @@ -649,8 +647,22 @@ class ShellTest extends CakeTestCase { $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()); + } }