Skip to content
Permalink
Browse files

Fixing issue where choices would not be correctly validated.

  • Loading branch information...
markstory committed Oct 11, 2010
1 parent 6774e40 commit 99407e788f352b3d994563fc3dde035aca485c3f
@@ -573,8 +573,8 @@ protected function _parseArg($argument, $args) {
if (!isset($this->_args[$next])) {
throw new InvalidArgumentException(__('Too many arguments.'));
}
$index = max($next - 1, 0);
if ($this->_args[$index]->validChoice($argument)) {
if ($this->_args[$next]->validChoice($argument)) {
array_push($args, $argument);
return $args;
}
@@ -282,13 +282,15 @@ function testPositionalArgNotEnough() {
*/
function testPositionalArgWithChoices() {
$parser = new ConsoleOptionParser();
$parser->addArgument('name', array('choices' => array('mark', 'jose')));
$parser->addArgument('name', array('choices' => array('mark', 'jose')))
->addArgument('alias', array('choices' => array('cowboy', 'samurai')))
->addArgument('weapon', array('choices' => array('gun', 'sword')));
$result = $parser->parse(array('mark'));
$expected = array('mark');
$result = $parser->parse(array('mark', 'samurai', 'sword'));
$expected = array('mark', 'samurai', 'sword');
$this->assertEquals($expected, $result[1], 'Got the correct value.');
$result = $parser->parse(array('jimmy'));
$result = $parser->parse(array('jose', 'coder'));
}
/**

0 comments on commit 99407e7

Please sign in to comment.
You can’t perform that action at this time.