Skip to content

Commit

Permalink
fix that argument with 0 as value will stop parsing args, tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
ceeram committed Jan 17, 2012
1 parent c81fe62 commit 8281175
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Console/ConsoleOptionParser.php
Expand Up @@ -467,7 +467,7 @@ public function parse($argv, $command = null) {
}
$params = $args = array();
$this->_tokens = $argv;
while ($token = array_shift($this->_tokens)) {
while (($token = array_shift($this->_tokens)) !== null) {
if (substr($token, 0, 2) == '--') {
$params = $this->_parseLongOption($token, $params);
} elseif (substr($token, 0, 1) == '-') {
Expand Down
13 changes: 13 additions & 0 deletions lib/Cake/Test/Case/Console/ConsoleOptionParserTest.php
Expand Up @@ -350,6 +350,19 @@ public function testParseArgumentTooMany() {
$result = $parser->parse(array('one', 'two', 'three'));
}

/**
* test parsing arguments with 0 value.
*
* @return void
*/
public function testParseArgumentZero() {
$parser = new ConsoleOptionParser('test', false);

$expected = array('one', 'two', 0, 'after', 'zero');
$result = $parser->parse($expected);
$this->assertEquals($expected, $result[1], 'Arguments are not as expected');
}

/**
* test that when there are not enough arguments an exception is raised
*
Expand Down

0 comments on commit 8281175

Please sign in to comment.