Checking if short options exist, fixed an warning caused by not checking it.

This commit is contained in:
Renan Gonçalves 2011-09-01 21:43:38 +02:00
parent 6f8869631f
commit 7ae89c3679
2 changed files with 15 additions and 0 deletions

View file

@ -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);
}

View file

@ -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.