Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7cb7655

Browse filesBrowse files
peterrehmfabpot
authored andcommitted
[Console][DX] Fixed ambiguous error message when using a duplicate option shortcut
1 parent 53b7236 commit 7cb7655
Copy full SHA for 7cb7655

File tree

Expand file treeCollapse file tree

2 files changed

+29
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Command/Command.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,14 @@ public function mergeApplicationDefinition($mergeArgs = true)
287287
return;
288288
}
289289

290+
$this->definition->addOptions($this->application->getDefinition()->getOptions());
291+
290292
if ($mergeArgs) {
291293
$currentArguments = $this->definition->getArguments();
292294
$this->definition->setArguments($this->application->getDefinition()->getArguments());
293295
$this->definition->addArguments($currentArguments);
294296
}
295297

296-
$this->definition->addOptions($this->application->getDefinition()->getOptions());
297-
298298
$this->applicationDefinitionMerged = true;
299299
if ($mergeArgs) {
300300
$this->applicationDefinitionMergedWithArgs = true;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/ApplicationTest.php
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,33 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
645645
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
646646
}
647647

648+
/**
649+
* @expectedException \LogicException
650+
* @expectedExceptionMessage An option with shortcut "e" already exists.
651+
*/
652+
public function testAddingOptionWithDuplicateShortcut()
653+
{
654+
$dispatcher = new EventDispatcher();
655+
$application = new Application();
656+
$application->setAutoExit(false);
657+
$application->setCatchExceptions(false);
658+
$application->setDispatcher($dispatcher);
659+
660+
$application->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'Environment'));
661+
662+
$application
663+
->register('foo')
664+
->setAliases(['f'])
665+
->setDefinition(array(new InputOption('survey', 'e', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')))
666+
->setCode(function (InputInterface $input, OutputInterface $output) {})
667+
;
668+
669+
$input = new ArrayInput(array('command' => 'foo'));
670+
$output = new NullOutput();
671+
672+
$application->run($input, $output);
673+
}
674+
648675
/**
649676
* @expectedException \LogicException
650677
* @dataProvider getAddingAlreadySetDefinitionElementData

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.