Skip to content

Commit 979bd62

Browse files
committed
bug symfony#22900 [FrameworkBundle][Console] Fix the override of a command registered by the kernel (aaa2000)
This PR was merged into the 2.7 branch. Discussion ---------- [FrameworkBundle][Console] Fix the override of a command registered by the kernel | Q | A | ------------- | --- | Branch? |2.7 | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | symfony#18558 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | <!--highly recommended for new features--> <!-- - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the 3.4, legacy code removals go to the master branch. - Please fill in this template according to the PR you're about to submit. - Replace this comment by a description of what your PR is solving. --> Fix the override of a command registered by the kernel Commits ------- 3e6643b [FrameworkBundle][Console] Fix the override of a command registered by the kernel
2 parents 3ac8c5b + 3e6643b commit 979bd62

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 11 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;
@@ -120,6 +121,16 @@ public function all($namespace = null)
120121
return parent::all($namespace);
121122
}
122123

124+
/**
125+
* {@inheritdoc}
126+
*/
127+
public function add(Command $command)
128+
{
129+
$this->registerCommands();
130+
131+
return parent::add($command);
132+
}
133+
123134
protected function registerCommands()
124135
{
125136
if ($this->commandsRegistered) {

src/Symfony/Bundle/FrameworkBundle/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)