@@ -32,8 +32,7 @@ public function testBundleInterfaceImplementation()
3232
3333 public function testBundleCommandsAreRegistered ()
3434 {
35- $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
36- $ bundle ->expects ($ this ->once ())->method ('registerCommands ' );
35+ $ bundle = $ this ->createBundleMock (array ());
3736
3837 $ kernel = $ this ->getKernel (array ($ bundle ), true );
3938
@@ -46,8 +45,7 @@ public function testBundleCommandsAreRegistered()
4645
4746 public function testBundleCommandsAreRetrievable ()
4847 {
49- $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
50- $ bundle ->expects ($ this ->once ())->method ('registerCommands ' );
48+ $ bundle = $ this ->createBundleMock (array ());
5149
5250 $ kernel = $ this ->getKernel (array ($ bundle ));
5351
@@ -60,47 +58,41 @@ public function testBundleCommandsAreRetrievable()
6058
6159 public function testBundleSingleCommandIsRetrievable ()
6260 {
63- $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
64- $ bundle ->expects ($ this ->once ())->method ('registerCommands ' );
61+ $ command = new Command ('example ' );
62+
63+ $ bundle = $ this ->createBundleMock (array ($ command ));
6564
6665 $ kernel = $ this ->getKernel (array ($ bundle ));
6766
6867 $ application = new Application ($ kernel );
6968
70- $ command = new Command ('example ' );
71- $ application ->add ($ command );
72-
7369 $ this ->assertSame ($ command , $ application ->get ('example ' ));
7470 }
7571
7672 public function testBundleCommandCanBeFound ()
7773 {
78- $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
79- $ bundle ->expects ($ this ->once ())->method ('registerCommands ' );
74+ $ command = new Command ('example ' );
75+
76+ $ bundle = $ this ->createBundleMock (array ($ command ));
8077
8178 $ kernel = $ this ->getKernel (array ($ bundle ));
8279
8380 $ application = new Application ($ kernel );
8481
85- $ command = new Command ('example ' );
86- $ application ->add ($ command );
87-
8882 $ this ->assertSame ($ command , $ application ->find ('example ' ));
8983 }
9084
9185 public function testBundleCommandCanBeFoundByAlias ()
9286 {
93- $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
94- $ bundle ->expects ($ this ->once ())->method ('registerCommands ' );
87+ $ command = new Command ('example ' );
88+ $ command ->setAliases (array ('alias ' ));
89+
90+ $ bundle = $ this ->createBundleMock (array ($ command ));
9591
9692 $ kernel = $ this ->getKernel (array ($ bundle ));
9793
9894 $ application = new Application ($ kernel );
9995
100- $ command = new Command ('example ' );
101- $ command ->setAliases (array ('alias ' ));
102- $ application ->add ($ command );
103-
10496 $ this ->assertSame ($ command , $ application ->find ('alias ' ));
10597 }
10698
@@ -167,4 +159,18 @@ private function getKernel(array $bundles, $useDispatcher = false)
167159
168160 return $ kernel ;
169161 }
162+
163+ private function createBundleMock (array $ commands )
164+ {
165+ $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
166+ $ bundle
167+ ->expects ($ this ->once ())
168+ ->method ('registerCommands ' )
169+ ->will ($ this ->returnCallback (function (Application $ application ) use ($ commands ) {
170+ $ application ->addCommands ($ commands );
171+ }))
172+ ;
173+
174+ return $ bundle ;
175+ }
170176}
0 commit comments