Permalink
Browse files

Checking if short options exist, fixed an warning caused by not check…

…ing it.
  • Loading branch information...
1 parent 6f88696 commit 7ae89c36794d22db8c41e14efb7ea73c85864f2f @renan renan committed Sep 1, 2011
Showing with 15 additions and 0 deletions.
  1. +3 −0 lib/Cake/Console/ConsoleOptionParser.php
  2. +12 −0 lib/Cake/Test/Case/Console/ConsoleOptionParserTest.php
@@ -561,6 +561,9 @@ protected function _parseShortOption($option, $params) {
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 @@ public function testOptionThatDoesNotExist() {
$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.

0 comments on commit 7ae89c3

Please sign in to comment.