Fixing issue where choices would not be correctly validated.

This commit is contained in:
mark_story 2010-10-11 01:51:00 -04:00
parent 6774e401fe
commit 99407e788f
2 changed files with 8 additions and 6 deletions

View file

@ -573,8 +573,8 @@ class ConsoleOptionParser {
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;
}

View file

@ -282,13 +282,15 @@ class ConsoleOptionParserTest extends CakeTestCase {
*/
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'));
}
/**