mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding tests for task methods in runCommand.
Moving startup() call to the dispatcher so nested runCommand calls don't double output the startup content.
This commit is contained in:
parent
cea9dadaa2
commit
79d1739778
3 changed files with 18 additions and 5 deletions
|
@ -329,8 +329,8 @@ class Shell extends Object {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function runCommand($command, $argv) {
|
public function runCommand($command, $argv) {
|
||||||
$this->startup();
|
|
||||||
if (!empty($command) && $this->hasTask($command)) {
|
if (!empty($command) && $this->hasTask($command)) {
|
||||||
|
$command = Inflector::camelize($command);
|
||||||
return $this->{$command}->runCommand('execute', $argv);
|
return $this->{$command}->runCommand('execute', $argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -269,6 +269,7 @@ class ShellDispatcher {
|
||||||
if ($Shell instanceof Shell) {
|
if ($Shell instanceof Shell) {
|
||||||
$Shell->initialize();
|
$Shell->initialize();
|
||||||
$Shell->loadTasks();
|
$Shell->loadTasks();
|
||||||
|
$Shell->startup();
|
||||||
return $Shell->runCommand($command, $this->args);
|
return $Shell->runCommand($command, $this->args);
|
||||||
}
|
}
|
||||||
$methods = array_diff(get_class_methods($Shell), get_class_methods('Shell'));
|
$methods = array_diff(get_class_methods($Shell), get_class_methods('Shell'));
|
||||||
|
|
|
@ -613,7 +613,6 @@ class ShellTest extends CakeTestCase {
|
||||||
$Mock = $this->getMock('Shell', array('main', 'startup'), array(), '', false);
|
$Mock = $this->getMock('Shell', array('main', 'startup'), array(), '', false);
|
||||||
|
|
||||||
$Mock->expects($this->once())->method('main')->will($this->returnValue(true));
|
$Mock->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
$Mock->expects($this->once())->method('startup');
|
|
||||||
$result = $Mock->runCommand(null, array());
|
$result = $Mock->runCommand(null, array());
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
@ -628,7 +627,6 @@ class ShellTest extends CakeTestCase {
|
||||||
$methods = get_class_methods('Shell');
|
$methods = get_class_methods('Shell');
|
||||||
$Mock = $this->getMock('Shell', array('startup'), array(), '', false);
|
$Mock = $this->getMock('Shell', array('startup'), array(), '', false);
|
||||||
|
|
||||||
$Mock->expects($this->once())->method('startup');
|
|
||||||
$Mock->expects($this->never())->method('hr');
|
$Mock->expects($this->never())->method('hr');
|
||||||
$result = $Mock->runCommand('hr', array());
|
$result = $Mock->runCommand('hr', array());
|
||||||
}
|
}
|
||||||
|
@ -638,7 +636,7 @@ class ShellTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testHelpParamTriggeringHelp() {
|
function testRunCommandTriggeringHelp() {
|
||||||
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
|
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
|
||||||
$Parser->expects($this->once())->method('parse')
|
$Parser->expects($this->once())->method('parse')
|
||||||
->with(array('--help'))
|
->with(array('--help'))
|
||||||
|
@ -649,8 +647,22 @@ class ShellTest extends CakeTestCase {
|
||||||
$Shell->expects($this->once())->method('_getOptionParser')
|
$Shell->expects($this->once())->method('_getOptionParser')
|
||||||
->will($this->returnValue($Parser));
|
->will($this->returnValue($Parser));
|
||||||
$Shell->expects($this->once())->method('out');
|
$Shell->expects($this->once())->method('out');
|
||||||
$Shell->expects($this->once())->method('startup');
|
|
||||||
|
|
||||||
$Shell->runCommand(null, array('--help'));
|
$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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue