Skip to content

Commit 6f05544

Browse files
committed
[Console] added an exception when overriding an existing argument (added some unit tests for option and arguments overriding)
1 parent 6d324a6 commit 6f05544

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,9 @@ private function mergeApplicationDefinition()
257257
return;
258258
}
259259

260-
$this->definition->setArguments(array_merge(
261-
$this->application->getDefinition()->getArguments(),
262-
$this->definition->getArguments()
263-
));
260+
$currentArguments = $this->definition->getArguments();
261+
$this->definition->setArguments($this->application->getDefinition()->getArguments());
262+
$this->definition->addArguments($currentArguments);
264263

265264
$this->definition->addOptions($this->application->getDefinition()->getOptions());
266265

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
use Symfony\Component\Console\Application;
1515
use Symfony\Component\Console\Output\Output;
1616
use Symfony\Component\Console\Tester\ApplicationTester;
17+
use Symfony\Component\Console\Input\InputArgument;
18+
use Symfony\Component\Console\Input\InputOption;
19+
use Symfony\Component\Console\Input\ArrayInput;
20+
use Symfony\Component\Console\Output\NullOutput;
1721

1822
class ApplicationTest extends \PHPUnit_Framework_TestCase
1923
{
@@ -346,4 +350,33 @@ public function testRun()
346350
$tester->run(array('command' => 'foo:bar', '-n' => true), array('decorated' => false));
347351
$this->assertEquals("called\n", $this->normalize($tester->getDisplay()), '->run() does not called interact() if -n is passed');
348352
}
353+
354+
/**
355+
* @expectedException \LogicException
356+
* @dataProvider getAddingAlreadySetDefinitionElementData
357+
*/
358+
public function testAddingAlreadySetDefinitionElementData($def)
359+
{
360+
$application = new Application();
361+
$application->setAutoExit(false);
362+
$application->setCatchExceptions(false);
363+
$application
364+
->register('foo')
365+
->setDefinition(array($def))
366+
->setCode(function (InputInterface $input, OutputInterface $output) {})
367+
;
368+
369+
$input = new ArrayInput(array('command' => 'foo'));
370+
$output = new NullOutput();
371+
$application->run($input, $output);
372+
}
373+
374+
public function getAddingAlreadySetDefinitionElementData()
375+
{
376+
return array(
377+
array(new InputArgument('command', InputArgument::REQUIRED)),
378+
array(new InputOption('quiet', '', InputOption::VALUE_NONE)),
379+
array(new InputOption('query', 'q', InputOption::VALUE_NONE)),
380+
);
381+
}
349382
}

‎tests/Symfony/Tests/Component/Console/Tester/ApplicationTesterTest.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ protected function setUp()
2525
$this->application = new Application();
2626
$this->application->setAutoExit(false);
2727
$this->application->register('foo')
28-
->addArgument('command')
2928
->addArgument('foo')
3029
->setCode(function ($input, $output) { $output->writeln('foo'); })
3130
;

0 commit comments

Comments
 (0)