Skip to content

Commit 137753d

Browse files
committed
bug symfony#27918 [Console] correctly return parameter's default value on "--" (seschwar)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] correctly return parameter's default value on "--" Fixes symfony#27916 | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#27916 | License | MIT | Doc PR | n/a The tests have been adjusted to use a default value different from the one in `A*Input::getParameterOption()`'s signature. This would have detected the bug in the first place and should prevent future regressions. Commits ------- d78dcc0 [Console] correctly return parameter's default value on "--"
2 parents 08b7874 + d78dcc0 commit 137753d

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function getParameterOption($values, $default = false, $onlyParams = fals
306306
while (0 < count($tokens)) {
307307
$token = array_shift($tokens);
308308
if ($onlyParams && '--' === $token) {
309-
return false;
309+
return $default;
310310
}
311311

312312
foreach ($values as $value) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getParameterOption($values, $default = false, $onlyParams = fals
8181

8282
foreach ($this->parameters as $k => $v) {
8383
if ($onlyParams && ('--' === $k || (is_int($k) && '--' === $v))) {
84-
return false;
84+
return $default;
8585
}
8686

8787
if (is_int($k)) {

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -395,25 +395,26 @@ public function testToString()
395395
/**
396396
* @dataProvider provideGetParameterOptionValues
397397
*/
398-
public function testGetParameterOptionEqualSign($argv, $key, $onlyParams, $expected)
398+
public function testGetParameterOptionEqualSign($argv, $key, $default, $onlyParams, $expected)
399399
{
400400
$input = new ArgvInput($argv);
401-
$this->assertEquals($expected, $input->getParameterOption($key, false, $onlyParams), '->getParameterOption() returns the expected value');
401+
$this->assertEquals($expected, $input->getParameterOption($key, $default, $onlyParams), '->getParameterOption() returns the expected value');
402402
}
403403

404404
public function provideGetParameterOptionValues()
405405
{
406406
return array(
407-
array(array('app/console', 'foo:bar', '-e', 'dev'), '-e', false, 'dev'),
408-
array(array('app/console', 'foo:bar', '--env=dev'), '--env', false, 'dev'),
409-
array(array('app/console', 'foo:bar', '-e', 'dev'), array('-e', '--env'), false, 'dev'),
410-
array(array('app/console', 'foo:bar', '--env=dev'), array('-e', '--env'), false, 'dev'),
411-
array(array('app/console', 'foo:bar', '--env=dev', '--en=1'), array('--en'), false, '1'),
412-
array(array('app/console', 'foo:bar', '--env=dev', '', '--en=1'), array('--en'), false, '1'),
413-
array(array('app/console', 'foo:bar', '--env', 'val'), '--env', false, 'val'),
414-
array(array('app/console', 'foo:bar', '--env', 'val', '--dummy'), '--env', false, 'val'),
415-
array(array('app/console', 'foo:bar', '--', '--env=dev'), '--env', false, 'dev'),
416-
array(array('app/console', 'foo:bar', '--', '--env=dev'), '--env', true, false),
407+
array(array('app/console', 'foo:bar'), '-e', 'default', false, 'default'),
408+
array(array('app/console', 'foo:bar', '-e', 'dev'), '-e', 'default', false, 'dev'),
409+
array(array('app/console', 'foo:bar', '--env=dev'), '--env', 'default', false, 'dev'),
410+
array(array('app/console', 'foo:bar', '-e', 'dev'), array('-e', '--env'), 'default', false, 'dev'),
411+
array(array('app/console', 'foo:bar', '--env=dev'), array('-e', '--env'), 'default', false, 'dev'),
412+
array(array('app/console', 'foo:bar', '--env=dev', '--en=1'), array('--en'), 'default', false, '1'),
413+
array(array('app/console', 'foo:bar', '--env=dev', '', '--en=1'), array('--en'), 'default', false, '1'),
414+
array(array('app/console', 'foo:bar', '--env', 'val'), '--env', 'default', false, 'val'),
415+
array(array('app/console', 'foo:bar', '--env', 'val', '--dummy'), '--env', 'default', false, 'val'),
416+
array(array('app/console', 'foo:bar', '--', '--env=dev'), '--env', 'default', false, 'dev'),
417+
array(array('app/console', 'foo:bar', '--', '--env=dev'), '--env', 'default', true, 'default'),
417418
);
418419
}
419420

src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ public function testGetParameterOption()
4747
{
4848
$input = new ArrayInput(array('name' => 'Fabien', '--foo' => 'bar'));
4949
$this->assertEquals('bar', $input->getParameterOption('--foo'), '->getParameterOption() returns the option of specified name');
50-
$this->assertFalse($input->getParameterOption('--bar'), '->getParameterOption() returns the default if an option is not present in the passed parameters');
50+
$this->assertEquals('default', $input->getParameterOption('--bar', 'default'), '->getParameterOption() returns the default value if an option is not present in the passed parameters');
5151

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

5555
$input = new ArrayInput(array('--foo', '--', '--bar' => 'woop'));
5656
$this->assertEquals('woop', $input->getParameterOption('--bar'), '->getParameterOption() returns the correct value if an option is present in the passed parameters');
57-
$this->assertFalse($input->getParameterOption('--bar', false, true), '->getParameterOption() returns false if an option is present in the passed parameters after an end of options signal');
57+
$this->assertEquals('default', $input->getParameterOption('--bar', 'default', true), '->getParameterOption() returns the default value if an option is present in the passed parameters after an end of options signal');
5858
}
5959

6060
public function testParseArguments()

0 commit comments

Comments
 (0)