Skip to content

Commit

Permalink
Shell methods will need to be camelCased, snake case is still accepted
Browse files Browse the repository at this point in the history
for invoking them. refs #2125
  • Loading branch information
lorenzo committed Jun 8, 2014
1 parent 92754d0 commit f94e9dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/Console/Shell.php
Expand Up @@ -259,7 +259,7 @@ public function hasTask($task) {
public function hasMethod($name) {
try {
$method = new \ReflectionMethod($this, $name);
if (!$method->isPublic() || substr($name, 0, 1) === '_') {
if (!$method->isPublic()) {
return false;
}
if ($method->getDeclaringClass()->name === 'Cake\Console\Shell') {
Expand Down Expand Up @@ -352,24 +352,24 @@ public function runCommand($argv, $autoMethod = false) {
}

$subcommands = $this->OptionParser->subcommands();
$isMethod = $this->hasMethod($command);
$method = Inflector::camelize($command);
$isMethod = $this->hasMethod($method);

if ($isMethod && $autoMethod && count($subcommands) === 0) {
array_shift($this->args);
$this->startup();
return call_user_func_array([$this, $command], $this->args);
return call_user_func_array([$this, $method], $this->args);
}

if ($isMethod && isset($subcommands[$command])) {
$this->startup();
return call_user_func_array([$this, $command], $this->args);
return call_user_func_array([$this, $method], $this->args);
}

if ($this->hasTask($command) && isset($subcommands[$command])) {
$this->startup();
$command = Inflector::camelize($command);
array_shift($argv);
return $this->{$command}->runCommand($argv, false);
return $this->{$method}->runCommand($argv, false);
}

if ($this->hasMethod('main')) {
Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -76,13 +76,13 @@ protected function _secret() {
}

//@codingStandardsIgnoreStart
public function do_something() {
public function doSomething() {
}

protected function no_access() {
protected function noAccess() {
}

public function log_something() {
public function logSomething() {
$this->log($this->testMessage);
}
//@codingStandardsIgnoreEnd
Expand Down Expand Up @@ -513,7 +513,7 @@ public function testHasTask() {
* @return void
*/
public function testHasMethod() {
$this->assertTrue($this->Shell->hasMethod('do_something'));
$this->assertTrue($this->Shell->hasMethod('doSomething'));
$this->assertFalse($this->Shell->hasMethod('hr'), 'hr is callable');
$this->assertFalse($this->Shell->hasMethod('_secret'), '_secret is callable');
$this->assertFalse($this->Shell->hasMethod('no_access'), 'no_access is callable');
Expand Down Expand Up @@ -543,10 +543,10 @@ public function testRunCommandMain() {
*/
public function testRunCommandWithMethod() {
$io = $this->getMock('Cake\Console\ConsoleIo');
$shell = $this->getMock('Cake\Console\Shell', ['hit_me', 'startup'], [$io]);
$shell = $this->getMock('Cake\Console\Shell', ['hitMe', 'startup'], [$io]);

$shell->expects($this->once())->method('startup');
$shell->expects($this->once())->method('hit_me')
$shell->expects($this->once())->method('hitMe')
->with('cakes')
->will($this->returnValue(true));
$result = $shell->runCommand(['hit_me', 'cakes', '--verbose'], true);
Expand Down

0 comments on commit f94e9dc

Please sign in to comment.