Skip to content

Commit 49cf461

Browse files
committed
Merge branch '2.8' into 3.2
* 2.8: [Console] ChoiceQuestion must have choices [Filesystem] improve error handling in lock() [FrameworkBundle][Console] Fix the override of a command registered by the kernel
2 parents f985afa + cebbad3 commit 49cf461

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Console/Application.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
1515
use Symfony\Component\Console\Application as BaseApplication;
16+
use Symfony\Component\Console\Command\Command;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Output\OutputInterface;
@@ -118,6 +119,13 @@ public function getLongVersion()
118119
return parent::getLongVersion().sprintf(' (kernel: <comment>%s</>, env: <comment>%s</>, debug: <comment>%s</>)', $this->kernel->getName(), $this->kernel->getEnvironment(), $this->kernel->isDebug() ? 'true' : 'false');
119120
}
120121

122+
public function add(Command $command)
123+
{
124+
$this->registerCommands();
125+
126+
return parent::add($command);
127+
}
128+
121129
protected function registerCommands()
122130
{
123131
if ($this->commandsRegistered) {

Tests/Console/ApplicationTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ public function testBundleCommandsHaveRightContainer()
115115
$tester->run(array('command' => 'foo'));
116116
}
117117

118+
public function testBundleCommandCanOverriddeAPreExistingCommandWithTheSameName()
119+
{
120+
$command = new Command('example');
121+
122+
$bundle = $this->createBundleMock(array($command));
123+
124+
$kernel = $this->getKernel(array($bundle));
125+
126+
$application = new Application($kernel);
127+
$newCommand = new Command('example');
128+
$application->add($newCommand);
129+
130+
$this->assertSame($newCommand, $application->get('example'));
131+
}
132+
118133
private function getKernel(array $bundles, $useDispatcher = false)
119134
{
120135
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();

0 commit comments

Comments
 (0)