File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 13
13
14
14
use Symfony \Component \DependencyInjection \ContainerAwareInterface ;
15
15
use Symfony \Component \Console \Application as BaseApplication ;
16
+ use Symfony \Component \Console \Command \Command ;
16
17
use Symfony \Component \Console \Input \InputInterface ;
17
18
use Symfony \Component \Console \Input \InputOption ;
18
19
use Symfony \Component \Console \Output \OutputInterface ;
@@ -122,6 +123,16 @@ public function all($namespace = null)
122
123
return parent ::all ($ namespace );
123
124
}
124
125
126
+ /**
127
+ * {@inheritdoc}
128
+ */
129
+ public function add (Command $ command )
130
+ {
131
+ $ this ->registerCommands ();
132
+
133
+ return parent ::add ($ command );
134
+ }
135
+
125
136
protected function registerCommands ()
126
137
{
127
138
if ($ this ->commandsRegistered ) {
Original file line number Diff line number Diff line change @@ -115,6 +115,21 @@ public function testBundleCommandsHaveRightContainer()
115
115
$ tester ->run (array ('command ' => 'foo ' ));
116
116
}
117
117
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
+
118
133
private function getKernel (array $ bundles , $ useDispatcher = false )
119
134
{
120
135
$ container = $ this ->getMockBuilder ('Symfony\Component\DependencyInjection\ContainerInterface ' )->getMock ();
You can’t perform that action at this time.
0 commit comments