8000 Merge branch '2.3' into 2.7 · symfony/symfony@13394f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 13394f8

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: [Console][DX] Fixed ambiguous error message when using a duplicate option shortcut
2 parents 71863ea + 60e6ccd commit 13394f8

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Symfony/Component/Console/Command/Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ public function mergeApplicationDefinition($mergeArgs = true)
297297
return;
298298
}
299299

300+
$this->definition->addOptions($this->application->getDefinition()->getOptions());
301+
300302
if ($mergeArgs) {
301303
$currentArguments = $this->definition->getArguments();
302304
$this->definition->setArguments($this->application->getDefinition()->getArguments());
303305
$this->definition->addArguments($currentArguments);
304306
}
305307

306-
$this->definition->addOptions($this->application->getDefinition()->getOptions());
307-
308308
$this->applicationDefinitionMerged = true;
309309
if ($mergeArgs) {
310310
$this->applicationDefinitionMergedWithArgs = true;

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,33 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
730730
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
731731
}
732732

733+
/**
734+
* @expectedException \LogicException
735+
* @expectedExceptionMessage An option with shortcut "e" already exists.
736+
*/
737+
public function testAddingOptionWithDuplicateShortcut()
738+
{
739+
$dispatcher = new EventDispatcher();
740+
$application = new Application();
741+
$application->setAutoExit(false);
742+
$application->setCatchExceptions(false);
743+
$application->setDispatcher($dispatcher);
744+
745+
$application->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'Environment'));
746+
747+
$application
748+
->register('foo')
749+
->setAliases(['f'])
750+
->setDefinition(array(new InputOption('survey', 'e', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')))
751+
->setCode(function (InputInterface $input, OutputInterface $output) {})
752+
;
753+
754+
$input = new ArrayInput(array('command' => 'foo'));
755+
$output = new NullOutput();
756+
757+
$application->run($input, $output);
758+
}
759+
733760
/**
734761
* @expectedException \LogicException
735762
* @dataProvider getAddingAlreadySetDefinitionElementData

0 commit comments

Comments
 (0)
0