mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix incorrect order of arguments when added out of sequence.
Fixes #3385
This commit is contained in:
parent
04d4abfa53
commit
587c7071b4
2 changed files with 21 additions and 1 deletions
|
@ -345,6 +345,7 @@ class ConsoleOptionParser {
|
||||||
$arg = new ConsoleInputArgument($options);
|
$arg = new ConsoleInputArgument($options);
|
||||||
}
|
}
|
||||||
$this->_args[$index] = $arg;
|
$this->_args[$index] = $arg;
|
||||||
|
ksort($this->_args);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -314,10 +314,29 @@ class ConsoleOptionParserTest extends CakeTestCase {
|
||||||
$parser = new ConsoleOptionParser('test', false);
|
$parser = new ConsoleOptionParser('test', false);
|
||||||
$parser->addArgument(new ConsoleInputArgument('test'));
|
$parser->addArgument(new ConsoleInputArgument('test'));
|
||||||
$result = $parser->arguments();
|
$result = $parser->arguments();
|
||||||
$this->assertEquals(1, count($result));
|
$this->assertCount(1, $result);
|
||||||
$this->assertEquals('test', $result[0]->name());
|
$this->assertEquals('test', $result[0]->name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test adding arguments out of order.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAddArgumentOutOfOrder() {
|
||||||
|
$parser = new ConsoleOptionParser('test', false);
|
||||||
|
$parser->addArgument('name', array('index' => 1, 'help' => 'first argument'))
|
||||||
|
->addArgument('bag', array('index' => 2, 'help' => 'second argument'))
|
||||||
|
->addArgument('other', array('index' => 0, 'help' => 'Zeroth argument'));
|
||||||
|
|
||||||
|
$result = $parser->arguments();
|
||||||
|
$this->assertCount(3, $result);
|
||||||
|
$this->assertEquals('other', $result[0]->name());
|
||||||
|
$this->assertEquals('name', $result[1]->name());
|
||||||
|
$this->assertEquals('bag', $result[2]->name());
|
||||||
|
$this->assertSame(array(0, 1, 2), array_keys($result));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test overwriting positional arguments.
|
* test overwriting positional arguments.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue