[Console][DX] Fixed ambiguous error message when using a duplicate option shortcut

This commit is contained in:
Peter Rehm 2016-05-25 08:27:19 +02:00 committed by Fabien Potencier
parent 53b7236fa8
commit 7cb76558ce
2 changed files with 29 additions and 2 deletions

View File

@ -287,14 +287,14 @@ class Command
return;
}
$this->definition->addOptions($this->application->getDefinition()->getOptions());
if ($mergeArgs) {
$currentArguments = $this->definition->getArguments();
$this->definition->setArguments($this->application->getDefinition()->getArguments());
$this->definition->addArguments($currentArguments);
}
$this->definition->addOptions($this->application->getDefinition()->getOptions());
$this->applicationDefinitionMerged = true;
if ($mergeArgs) {
$this->applicationDefinitionMergedWithArgs = true;

View File

@ -645,6 +645,33 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage An option with shortcut "e" already exists.
*/
public function testAddingOptionWithDuplicateShortcut()
{
$dispatcher = new EventDispatcher();
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->setDispatcher($dispatcher);
$application->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'Environment'));
$application
->register('foo')
->setAliases(['f'])
->setDefinition(array(new InputOption('survey', 'e', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')))
->setCode(function (InputInterface $input, OutputInterface $output) {})
;
$input = new ArrayInput(array('command' => 'foo'));
$output = new NullOutput();
$application->run($input, $output);
}
/**
* @expectedException \LogicException
* @dataProvider getAddingAlreadySetDefinitionElementData