Skip to content

Commit

Permalink
[Console] fixed ArrayInput, if array contains 0 key.
Browse files Browse the repository at this point in the history
  • Loading branch information
arima-ryunosuke authored and fabpot committed Feb 11, 2015
1 parent 917067e commit a642e4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Symfony/Component/Console/Input/ArrayInput.php
Expand Up @@ -100,8 +100,10 @@ public function getParameterOption($values, $default = false)
$values = (array) $values;

foreach ($this->parameters as $k => $v) {
if (is_int($k) && in_array($v, $values)) {
return true;
if (is_int($k)) {
if (in_array($v, $values)) {
return true;
}
} elseif (in_array($k, $values)) {
return $v;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php
Expand Up @@ -38,6 +38,15 @@ public function testHasParameterOption()
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');
}

public function testGetParameterOption()
{
$input = new ArrayInput(array('name' => 'Fabien', '--foo' => 'bar'));
$this->assertEquals('bar', $input->getParameterOption('--foo'), '->getParameterOption() returns the option of specified name');

$input = new ArrayInput(array('Fabien', '--foo' => 'bar'));
$this->assertEquals('bar', $input->getParameterOption('--foo'), '->getParameterOption() returns the option of specified name');
}

public function testParseArguments()
{
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
Expand Down

0 comments on commit a642e4b

Please sign in to comment.