mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #10916 from tenkoma/2.x-console-unknown-option
2.x Console: Display error message when unknown option is specified
This commit is contained in:
commit
1eb4b0fdf7
2 changed files with 27 additions and 0 deletions
|
@ -431,6 +431,7 @@ class Shell extends CakeObject {
|
||||||
try {
|
try {
|
||||||
list($this->params, $this->args) = $this->OptionParser->parse($argv, $command);
|
list($this->params, $this->args) = $this->OptionParser->parse($argv, $command);
|
||||||
} catch (ConsoleException $e) {
|
} catch (ConsoleException $e) {
|
||||||
|
$this->err(__d('cake_console', '<error>Error:</error> %s', $e->getMessage()));
|
||||||
$this->out($this->OptionParser->help($command));
|
$this->out($this->OptionParser->help($command));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -778,6 +778,32 @@ class ShellTest extends CakeTestCase {
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test unknown option causes display of error and help.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testRunCommandUnknownOption() {
|
||||||
|
$output = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
||||||
|
$error = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
||||||
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
||||||
|
|
||||||
|
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
|
||||||
|
$Parser->expects($this->once())->method('parse')
|
||||||
|
->with(array('--unknown'))
|
||||||
|
->will($this->throwException(new ConsoleException('Unknown option `unknown`')));
|
||||||
|
$Parser->expects($this->once())->method('help');
|
||||||
|
|
||||||
|
$Shell = $this->getMock('ShellTestShell', array('getOptionParser'), array($output, $error, $in));
|
||||||
|
|
||||||
|
$Shell->expects($this->once())->method('getOptionParser')
|
||||||
|
->will($this->returnValue($Parser));
|
||||||
|
$Shell->stderr->expects($this->once())->method('write');
|
||||||
|
$Shell->stdout->expects($this->once())->method('write');
|
||||||
|
|
||||||
|
$Shell->runCommand('do_something', array('do_something', '--unknown'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that a --help causes help to show.
|
* test that a --help causes help to show.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue