[FrameworkBundle][Console] Fix the override of a command registered by the kernel

Fix #18558
This commit is contained in:
adev 2017-05-24 23:07:05 +02:00
parent 49d6604ee4
commit 3e6643bd90
2 changed files with 26 additions and 0 deletions

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Console;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@ -120,6 +121,16 @@ class Application extends BaseApplication
return parent::all($namespace);
}
/**
* {@inheritdoc}
*/
public function add(Command $command)
{
$this->registerCommands();
return parent::add($command);
}
protected function registerCommands()
{
if ($this->commandsRegistered) {

View File

@ -115,6 +115,21 @@ class ApplicationTest extends TestCase
$tester->run(array('command' => 'foo'));
}
public function testBundleCommandCanOverriddeAPreExistingCommandWithTheSameName()
{
$command = new Command('example');
$bundle = $this->createBundleMock(array($command));
$kernel = $this->getKernel(array($bundle));
$application = new Application($kernel);
$newCommand = new Command('example');
$application->add($newCommand);
$this->assertSame($newCommand, $application->get('example'));
}
private function getKernel(array $bundles, $useDispatcher = false)
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();