Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pass positional arguments into shell methods.
Much like controllers, shells now get positional arguments as method
parameters. This makes it easier to work with positional arguments, as
you don't need to use $this->args.

Refs #3325
  • Loading branch information
markstory committed Apr 18, 2014
1 parent faf7b18 commit 9e0da22
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Console/Shell.php
Expand Up @@ -374,10 +374,10 @@ public function runCommand($command, $argv) {
return $this->{$command}->runCommand('execute', $argv);
}
if ($isMethod) {
return $this->{$command}();
return call_user_func_array([$this, $command], $this->args);
}
if ($isMain) {
return $this->main();
return call_user_func_array([$this, 'main'], $this->args);
}
$this->out($this->OptionParser->help($command));
return false;
Expand Down
28 changes: 18 additions & 10 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -523,10 +523,14 @@ public function testHasMethod() {
* @return void
*/
public function testRunCommandMain() {
$Mock = $this->getMock('Cake\Console\Shell', array('main', 'startup'), array(), '', false);
$io = $this->getMock('Cake\Console\ConsoleIo');
$Mock = $this->getMock('Cake\Console\Shell', ['main', 'startup'], [$io]);

$Mock->expects($this->once())->method('main')->will($this->returnValue(true));
$result = $Mock->runCommand(null, array());
$Mock->expects($this->once())->method('startup');
$Mock->expects($this->once())->method('main')
->with('cakes')
->will($this->returnValue(true));
$result = $Mock->runCommand(null, ['cakes', '--verbose']);
$this->assertTrue($result);
}

Expand All @@ -536,10 +540,14 @@ public function testRunCommandMain() {
* @return void
*/
public function testRunCommandWithMethod() {
$Mock = $this->getMock('Cake\Console\Shell', array('hit_me', 'startup'), array(), '', false);
$io = $this->getMock('Cake\Console\ConsoleIo');
$Mock = $this->getMock('Cake\Console\Shell', ['hit_me', 'startup'], [$io]);

$Mock->expects($this->once())->method('hit_me')->will($this->returnValue(true));
$result = $Mock->runCommand('hit_me', array());
$Mock->expects($this->once())->method('startup');
$Mock->expects($this->once())->method('hit_me')
->with('cakes')
->will($this->returnValue(true));
$result = $Mock->runCommand('hit_me', ['hit_me', 'cakes', '--verbose']);
$this->assertTrue($result);
}

Expand Down Expand Up @@ -606,11 +614,11 @@ public function testRunCommandTriggeringHelp() {
* @return void
*/
public function testRunCommandHittingTask() {
$Shell = $this->getMock('Cake\Console\Shell', array('hasTask', 'startup'), array(), '', false);
$task = $this->getMock('Cake\Console\Shell', array('execute', 'runCommand'), array(), '', false);
$Shell = $this->getMock('Cake\Console\Shell', ['hasTask', 'startup'], [], '', false);
$task = $this->getMock('Cake\Console\Shell', ['execute', 'runCommand'], [], '', false);
$task->expects($this->any())
->method('runCommand')
->with('execute', array('one', 'value'));
->with('execute', ['one', 'value']);

$Shell->expects($this->once())->method('startup');
$Shell->expects($this->any())
Expand All @@ -619,7 +627,7 @@ public function testRunCommandHittingTask() {

$Shell->RunCommand = $task;

$Shell->runCommand('run_command', array('run_command', 'one', 'value'));
$Shell->runCommand('run_command', ['run_command', 'one', 'value']);
}

/**
Expand Down

0 comments on commit 9e0da22

Please sign in to comment.