fix that argument with 0 as value will stop parsing args, tests added

This commit is contained in:
Ceeram 2012-01-17 20:01:16 +01:00
parent c81fe6249d
commit 828117583f
2 changed files with 14 additions and 1 deletions

View file

@ -467,7 +467,7 @@ class ConsoleOptionParser {
}
$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) == '-') {

View file

@ -350,6 +350,19 @@ class ConsoleOptionParserTest extends CakeTestCase {
$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
*