8000 Merge remote branch 'Herzult/fixArrayOption' · renegare/symfony@c6cfd3a · GitHub
[go: up one dir, main page]

Skip to content

Commit c6cfd3a

Browse files
committed
Merge remote branch 'Herzult/fixArrayOption'
* Herzult/fixArrayOption: Simplify conditional block [Command] Fix array option parsing
2 parents adc7904 + d9f00ca commit c6cfd3a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ private function addLongOption($name, $value)
229229
$value = $option->isValueOptional() ? $option->getDefault() : true;
230230
}
231231

232-
$this->options[$name] = $value;
232+
if ($option->isArray()) {
233+
$this->options[$name][] = $value;
234+
} else {
235+
$this->options[$name] = $value;
236+
}
233237
}
234238

235239
/**

tests/Symfony/Tests/Component/Console/Input/ArgvInputTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ public function testParser()
147147
} catch (\RuntimeException $e) {
148148
$this->assertNotEquals('Too many arguments.', $e->getMessage(), '->parse() parses array arguments');
149149
}
150+
151+
$input = new ArgvInput(array('cli.php', '--name=foo', '--name=bar', '--name=baz'));
152+
$input->bind(new InputDefinition(array(new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY))));
153+
$this->assertEquals(array('name' => array('foo', 'bar', 'baz')), $input->getOptions());
150154
}
151155

152156
public function testGetFirstArgument()

0 commit comments

Comments
 (0)
0