[Console][DX] Fixed ambiguous error message when using a duplicate option shortcut
This commit is contained in:
parent
53b7236fa8
commit
7cb76558ce
@ -287,14 +287,14 @@ class Command
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->definition->addOptions($this->application->getDefinition()->getOptions());
|
||||||
|
|
||||||
if ($mergeArgs) {
|
if ($mergeArgs) {
|
||||||
$currentArguments = $this->definition->getArguments();
|
$currentArguments = $this->definition->getArguments();
|
||||||
$this->definition->setArguments($this->application->getDefinition()->getArguments());
|
$this->definition->setArguments($this->application->getDefinition()->getArguments());
|
||||||
$this->definition->addArguments($currentArguments);
|
$this->definition->addArguments($currentArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->definition->addOptions($this->application->getDefinition()->getOptions());
|
|
||||||
|
|
||||||
$this->applicationDefinitionMerged = true;
|
$this->applicationDefinitionMerged = true;
|
||||||
if ($mergeArgs) {
|
if ($mergeArgs) {
|
||||||
$this->applicationDefinitionMergedWithArgs = true;
|
$this->applicationDefinitionMergedWithArgs = true;
|
||||||
|
@ -645,6 +645,33 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
|
$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
|
* @expectedException \LogicException
|
||||||
* @dataProvider getAddingAlreadySetDefinitionElementData
|
* @dataProvider getAddingAlreadySetDefinitionElementData
|
||||||
|
Reference in New Issue
Block a user