Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix incorrect order of arguments when added out of sequence.
Fixes #3385
  • Loading branch information
markstory committed Nov 21, 2012
1 parent 04d4abf commit 587c707
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/Cake/Console/ConsoleOptionParser.php
Expand Up @@ -345,6 +345,7 @@ public function addArgument($name, $params = array()) {
$arg = new ConsoleInputArgument($options);
}
$this->_args[$index] = $arg;
ksort($this->_args);
return $this;
}

Expand Down
21 changes: 20 additions & 1 deletion lib/Cake/Test/Case/Console/ConsoleOptionParserTest.php
Expand Up @@ -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.
*
Expand Down

0 comments on commit 587c707

Please sign in to comment.