From 79d1739778d54088074249980ee86d265d831e69 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 9 Oct 2010 23:30:56 -0400 Subject: [PATCH] Adding tests for task methods in runCommand. Moving startup() call to the dispatcher so nested runCommand calls don't double output the startup content. --- cake/console/libs/shell.php | 2 +- cake/console/shell_dispatcher.php | 1 + cake/tests/cases/console/libs/shell.test.php | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index 7daabc0817b..3b9fe1304b8 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -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); } diff --git a/cake/console/shell_dispatcher.php b/cake/console/shell_dispatcher.php index 338278748cd..a7616a5d1af 100644 --- a/cake/console/shell_dispatcher.php +++ b/cake/console/shell_dispatcher.php @@ -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')); diff --git a/cake/tests/cases/console/libs/shell.test.php b/cake/tests/cases/console/libs/shell.test.php index 45a25075adf..f57650d6e7e 100644 --- a/cake/tests/cases/console/libs/shell.test.php +++ b/cake/tests/cases/console/libs/shell.test.php @@ -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); } @@ -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()); } @@ -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')) @@ -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()); + } }