Skip to content

Commit

Permalink
Fixing issue where choices would not be correctly validated.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 14, 2010
1 parent 6774e40 commit 99407e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cake/console/console_option_parser.php
Expand Up @@ -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;
}
Expand Down
10 changes: 6 additions & 4 deletions cake/tests/cases/console/console_option_parser.test.php
Expand Up @@ -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'));
}

/**
Expand Down

0 comments on commit 99407e7

Please sign in to comment.