Skip to content
Permalink
Browse files

Fix incorrect order of arguments when added out of sequence.

Fixes #3385
  • Loading branch information...
markstory committed Nov 21, 2012
1 parent 04d4abf commit 587c7071b4448fab8f185110993e035b5a6c38a3
@@ -345,6 +345,7 @@ public function addArgument($name, $params = array()) {
$arg = new ConsoleInputArgument($options);
}
$this->_args[$index] = $arg;
ksort($this->_args);
return $this;
}
@@ -314,10 +314,29 @@ public function testAddArgumentObject() {
$parser = new ConsoleOptionParser('test', false);
$parser->addArgument(new ConsoleInputArgument('test'));
$result = $parser->arguments();
$this->assertEquals(1, count($result));
$this->assertCount(1, $result);
$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.
*

0 comments on commit 587c707

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.