15
15
use Symfony \Bundle \FrameworkBundle \Console \Application ;
16
16
use Symfony \Component \Console \Input \ArrayInput ;
17
17
use Symfony \Component \Console \Output \NullOutput ;
18
+ use Symfony \Component \Console \Tester \ApplicationTester ;
18
19
19
20
class ApplicationTest extends TestCase
20
21
{
@@ -39,6 +40,25 @@ public function testBundleCommandsAreRegistered()
39
40
$ application ->doRun (new ArrayInput (array ('list ' )), new NullOutput ());
40
41
}
41
42
43
+ public function testBundleCommandsHaveRightContainer ()
44
+ {
45
+ $ command = $ this ->getMockForAbstractClass ('Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand ' , array ('foo ' ), '' , true , true , true , array ('setContainer ' ));
46
+ $ command ->setCode (function () {});
47
+ $ command ->expects ($ this ->exactly (2 ))->method ('setContainer ' );
48
+
49
+ $ application = new Application ($ this ->getKernel (array ()));
50
+ $ application ->setAutoExit (false );
51
+ $ application ->setCatchExceptions (false );
52
+ $ application ->add ($ command );
53
+ $ tester = new ApplicationTester ($ application );
54
+
55
+ // set container is called here
56
+ $ tester ->run (array ('command ' => 'foo ' ));
57
+
58
+ // as the container might have change between two runs, setContainer must called again
59
+ $ tester ->run (array ('command ' => 'foo ' ));
60
+ }
61
+
42
62
private function getKernel (array $ bundles )
43
63
{
44
64
$ dispatcher = $ this ->getMock ('Symfony\Component\EventDispatcher\EventDispatcherInterface ' );
@@ -49,7 +69,7 @@ private function getKernel(array $bundles)
49
69
50
70
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
51
71
$ container
52
- ->expects ($ this ->once ())
72
+ ->expects ($ this ->atLeastOnce ())
53
73
->method ('get ' )
54
74
->with ($ this ->equalTo ('event_dispatcher ' ))
55
75
->will ($ this ->returnValue ($ dispatcher ))
0 commit comments