@@ -32,8 +32,7 @@ public function testBundleInterfaceImplementation()
32
32
33
33
public function testBundleCommandsAreRegistered ()
34
34
{
35
- $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
36
- $ bundle ->expects ($ this ->once ())->method ('registerCommands ' );
35
+ $ bundle = $ this ->createBundleMock (array ());
37
36
38
37
$ kernel = $ this ->getKernel (array ($ bundle ), true );
39
38
@@ -46,8 +45,7 @@ public function testBundleCommandsAreRegistered()
46
45
47
46
public function testBundleCommandsAreRetrievable ()
48
47
{
49
- $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
50
- $ bundle ->expects ($ this ->once ())->method ('registerCommands ' );
48
+ $ bundle = $ this ->createBundleMock (array ());
51
49
52
50
$ kernel = $ this ->getKernel (array ($ bundle ));
53
51
@@ -60,47 +58,41 @@ public function testBundleCommandsAreRetrievable()
60
58
61
59
public function testBundleSingleCommandIsRetrievable ()
62
60
{
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 ));
65
64
66
65
$ kernel = $ this ->getKernel (array ($ bundle ));
67
66
68
67
$ application = new Application ($ kernel );
69
68
70
- $ command = new Command ('example ' );
71
- $ application ->add ($ command );
72
-
73
69
$ this ->assertSame ($ command , $ application ->get ('example ' ));
74
70
}
75
71
76
72
public function testBundleCommandCanBeFound ()
77
73
{
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 ));
80
77
81
78
$ kernel = $ this ->getKernel (array ($ bundle ));
82
79
83
80
$ application = new Application ($ kernel );
84
81
85
- $ command = new Command ('example ' );
86
- $ application ->add ($ command );
87
-
88
82
$ this ->assertSame ($ command , $ application ->find ('example ' ));
89
83
}
90
84
91
85
public function testBundleCommandCanBeFoundByAlias ()
92
86
{
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 ));
95
91
96
92
$ kernel = $ this ->getKernel (array ($ bundle ));
97
93
98
94
$ application = new Application ($ kernel );
99
95
100
- $ command = new Command ('example ' );
101
- $ command ->setAliases (array ('alias ' ));
102
- $ application ->add ($ command );
103
-
104
96
$ this ->assertSame ($ command , $ application ->find ('alias ' ));
105
97
}
106
98
@@ -167,4 +159,18 @@ private function getKernel(array $bundles, $useDispatcher = false)
167
159
168
160
return $ kernel ;
169
161
}
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
+ }
170
176
}
0 commit comments