Fixes for hasParameterOption and getParameterOption methods of ArgvInput

This commit is contained in:
Vasily Khayrulin 2013-08-15 17:16:55 +04:00 committed by Fabien Potencier
parent d60fa064f3
commit ab9a96b774
2 changed files with 10 additions and 4 deletions

View File

@ -284,11 +284,13 @@ class ArgvInput extends Input
{ {
$values = (array) $values; $values = (array) $values;
foreach ($this->tokens as $v) { foreach ($this->tokens as $token) {
if (in_array($v, $values)) { foreach ($values as $value) {
if ($token === $value || 0 === strpos($token, $value . '=')) {
return true; return true;
} }
} }
}
return false; return false;
} }
@ -311,7 +313,7 @@ class ArgvInput extends Input
$tokens = $this->tokens; $tokens = $this->tokens;
while ($token = array_shift($tokens)) { while ($token = array_shift($tokens)) {
foreach ($values as $value) { foreach ($values as $value) {
if (0 === strpos($token, $value)) { if ($token === $value || 0 === strpos($token, $value . '=')) {
if (false !== $pos = strpos($token, '=')) { if (false !== $pos = strpos($token, '=')) {
return substr($token, $pos + 1); return substr($token, $pos + 1);
} }

View File

@ -230,6 +230,9 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
$input = new ArgvInput(array('cli.php', 'foo')); $input = new ArgvInput(array('cli.php', 'foo'));
$this->assertFalse($input->hasParameterOption('--foo'), '->hasParameterOption() returns false if the given short option is not in the raw input'); $this->assertFalse($input->hasParameterOption('--foo'), '->hasParameterOption() returns false if the given short option is not in the raw input');
$input = new ArgvInput(array('cli.php', '--foo=bar'));
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given option with provided value is in the raw input');
} }
/** /**
@ -248,6 +251,7 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
array(array('app/console', 'foo:bar', '--env=dev'), '--env', 'dev'), array(array('app/console', 'foo:bar', '--env=dev'), '--env', 'dev'),
array(array('app/console', 'foo:bar', '-e', 'dev'), array('-e', '--env'), 'dev'), array(array('app/console', 'foo:bar', '-e', 'dev'), array('-e', '--env'), 'dev'),
array(array('app/console', 'foo:bar', '--env=dev'), array('-e', '--env'), 'dev'), array(array('app/console', 'foo:bar', '--env=dev'), array('-e', '--env'), 'dev'),
array(array('app/console', 'foo:bar', '--env=dev', '--en=1'), array('--en'), '1'),
); );
} }
} }