mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding exception for unknown option usage.
This commit is contained in:
parent
d3c95bc2c4
commit
7f5b5c4fbd
2 changed files with 16 additions and 2 deletions
|
@ -420,6 +420,9 @@ class ConsoleOptionParser {
|
|||
* @return array Params with $option added in.
|
||||
*/
|
||||
protected function _parseOptionName($name, $params) {
|
||||
if (!isset($this->_options[$name])) {
|
||||
throw new InvalidArgumentException(sprintf(__('Unknown option `%s`'), $name));
|
||||
}
|
||||
$definition = $this->_options[$name];
|
||||
$nextValue = $this->_nextToken();
|
||||
if (!$definition['boolean'] && !empty($nextValue) && $nextValue{0} != '-') {
|
||||
|
|
|
@ -159,11 +159,22 @@ class ConsoleOptionParserTest extends CakeTestCase {
|
|||
$parser = new ConsoleOptionParser();
|
||||
$parser->addOption('no-commit', array('boolean' => true))
|
||||
->addOption('table', array('short' => 't'));
|
||||
|
||||
|
||||
$result = $parser->parse(array('--table', 'posts', '--no-commit', 'arg1', 'arg2'));
|
||||
$expected = array(array('table' => 'posts', 'no-commit' => true), array('arg1', 'arg2'));
|
||||
$this->assertEquals($expected, $result, 'Boolean option did not parse correctly.');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test parsing options that do not exist.
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
function testOptionThatDoesNotExist() {
|
||||
$parser = new ConsoleOptionParser();
|
||||
$parser->addOption('no-commit', array('boolean' => true));
|
||||
|
||||
$result = $parser->parse(array('--fail', 'other'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue