Skip to content
Permalink
Browse files

Making a missing method generate help, when a shell lacks a main() me…

…thod.
  • Loading branch information...
markstory committed Oct 16, 2010
1 parent a234eeb commit e85482f702e1d87a15bcd5cdbf39590962ff55d5
Showing with 16 additions and 6 deletions.
  1. +1 −1 cake/console/libs/shell.php
  2. +15 −5 cake/tests/cases/console/libs/shell.test.php
@@ -352,7 +352,7 @@ public function runCommand($command, $argv) {
if ($isMain) {
return $this->main();
}
throw new MissingShellMethodException(array('shell' => get_class($this), 'method' => $command));
return $this->out($this->OptionParser->help($command));
}
/**
@@ -657,28 +657,38 @@ function testRunCommandMain() {
/**
* test run command causing exception on Shell method.
*
* @expectedException MissingShellMethodException
* @return void
*/
function testRunCommandBaseclassMethod() {
$methods = get_class_methods('Shell');
$Mock = $this->getMock('Shell', array('startup'), array(), '', false);
$Mock = $this->getMock('Shell', array('startup', 'getOptionParser', 'out'), array(), '', false);
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
$Parser->expects($this->once())->method('help');
$Mock->expects($this->once())->method('getOptionParser')
->will($this->returnValue($Parser));
$Mock->expects($this->never())->method('hr');
$Mock->expects($this->once())->method('out');
$result = $Mock->runCommand('hr', array());
}
/**
* test run command causing exception on Shell method.
*
* @expectedException MissingShellMethodException
* @return void
*/
function testRunCommandMissingMethod() {
$methods = get_class_methods('Shell');
$Mock = $this->getMock('Shell', array('startup'), array(), '', false);
$Mock = $this->getMock('Shell', array('startup', 'getOptionParser', 'out'), array(), '', false);
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
$Parser->expects($this->once())->method('help');
$Mock->expects($this->never())->method('idontexist');
$Mock->expects($this->once())->method('getOptionParser')
->will($this->returnValue($Parser));
$Mock->expects($this->once())->method('out');
$result = $Mock->runCommand('idontexist', array());
}

0 comments on commit e85482f

Please sign in to comment.
You can’t perform that action at this time.