Skip to content

Commit

Permalink
Fixes for hasParameterOption and getParameterOption methods of ArgvInput
Browse files Browse the repository at this point in the history
  • Loading branch information
sirian authored and fabpot committed Aug 17, 2013
1 parent d60fa06 commit ab9a96b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Symfony/Component/Console/Input/ArgvInput.php
Expand Up @@ -284,9 +284,11 @@ public function hasParameterOption($values)
{
$values = (array) $values;

foreach ($this->tokens as $v) {
if (in_array($v, $values)) {
return true;
foreach ($this->tokens as $token) {
foreach ($values as $value) {
if ($token === $value || 0 === strpos($token, $value . '=')) {
return true;
}
}
}

Expand All @@ -311,7 +313,7 @@ public function getParameterOption($values, $default = false)
$tokens = $this->tokens;
while ($token = array_shift($tokens)) {
foreach ($values as $value) {
if (0 === strpos($token, $value)) {
if ($token === $value || 0 === strpos($token, $value . '=')) {
if (false !== $pos = strpos($token, '=')) {
return substr($token, $pos + 1);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
Expand Up @@ -230,6 +230,9 @@ public function testHasParameterOption()

$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');

$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');
}

/**
Expand All @@ -248,6 +251,7 @@ public function provideGetParameterOptionValues()
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', '--env=dev'), array('-e', '--env'), 'dev'),
array(array('app/console', 'foo:bar', '--env=dev', '--en=1'), array('--en'), '1'),
);
}
}

0 comments on commit ab9a96b

Please sign in to comment.