Merge branch '2.3' into 2.7

* 2.3:
  [Console][DX] Fixed ambiguous error message when using a duplicate option shortcut
This commit is contained in:
Fabien Potencier 2016-05-26 09:56:29 +02:00
commit 13394f81f7
2 changed files with 29 additions and 2 deletions

View File

@ -297,14 +297,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

@ -730,6 +730,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