Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix incorrect order of arguments when added out of sequence.

Fixes #3385
  • Loading branch information...
commit 587c7071b4448fab8f185110993e035b5a6c38a3 1 parent 04d4abf
@markstory markstory authored
View
1  lib/Cake/Console/ConsoleOptionParser.php
@@ -345,6 +345,7 @@ public function addArgument($name, $params = array()) {
$arg = new ConsoleInputArgument($options);
}
$this->_args[$index] = $arg;
+ ksort($this->_args);
return $this;
}
View
21 lib/Cake/Test/Case/Console/ConsoleOptionParserTest.php
@@ -314,11 +314,30 @@ 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.
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.