mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixing issue where choices would not be correctly validated.
This commit is contained in:
parent
6774e401fe
commit
99407e788f
2 changed files with 8 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue