mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Checking if short options exist, fixed an warning caused by not checking it.
This commit is contained in:
parent
6f8869631f
commit
7ae89c3679
2 changed files with 15 additions and 0 deletions
|
@ -561,6 +561,9 @@ class ConsoleOptionParser {
|
|||
array_unshift($this->_tokens, '-' . $flags[$i]);
|
||||
}
|
||||
}
|
||||
if (!isset($this->_shortOptions[$key])) {
|
||||
throw new ConsoleException(__d('cake_console', 'Unknown short option `%s`', $key));
|
||||
}
|
||||
$name = $this->_shortOptions[$key];
|
||||
return $this->_parseOption($name, $params);
|
||||
}
|
||||
|
|
|
@ -249,6 +249,18 @@ class ConsoleOptionParserTest extends CakeTestCase {
|
|||
|
||||
$result = $parser->parse(array('--fail', 'other'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test parsing short options that do not exist.
|
||||
*
|
||||
* @expectedException ConsoleException
|
||||
*/
|
||||
public function testShortOptionThatDoesNotExist() {
|
||||
$parser = new ConsoleOptionParser('test', false);
|
||||
$parser->addOption('no-commit', array('boolean' => true));
|
||||
|
||||
$result = $parser->parse(array('-f'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that options with choices enforce them.
|
||||
|
|
Loading…
Reference in a new issue