1111
1212namespace Symfony \Bundle \FrameworkBundle \Tests \Console ;
1313
14- use Symfony \Bundle \FrameworkBundle \Tests \TestCase ;
1514use Symfony \Bundle \FrameworkBundle \Console \Application ;
15+ use Symfony \Bundle \FrameworkBundle \Tests \TestCase ;
16+ use Symfony \Component \Console \Command \Command ;
1617use Symfony \Component \Console \Input \ArrayInput ;
1718use Symfony \Component \Console \Output \NullOutput ;
1819use Symfony \Component \Console \Tester \ApplicationTester ;
@@ -38,6 +39,89 @@ public function testBundleCommandsAreRegistered()
3839
3940 $ application = new Application ($ kernel );
4041 $ application ->doRun (new ArrayInput (array ('list ' )), new NullOutput ());
42+
43+ // Calling twice: registration should only be done once.
44+ $ application ->doRun (new ArrayInput (array ('list ' )), new NullOutput ());
45+ }
46+
47+ public function testBundleCommandsAreRetrievable ()
48+ {
49+ $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
50+ $ bundle ->expects ($ this ->once ())->method ('registerCommands ' );
51+
52+ $ kernel = $ this ->getMock ('Symfony\Component\HttpKernel\KernelInterface ' );
53+ $ kernel
54+ ->expects ($ this ->any ())
55+ ->method ('getBundles ' )
56+ ->will ($ this ->returnValue (array ($ bundle )))
57+ ;
58+
59+ $ application = new Application ($ kernel );
60+ $ application ->all ();
61+
62+ // Calling twice: registration should only be done once.
63+ $ application ->all ();
64+ }
65+
66+ public function testBundleSingleCommandIsRetrievable ()
67+ {
68+ $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
69+ $ bundle ->expects ($ this ->once ())->method ('registerCommands ' );
70+
71+ $ kernel = $ this ->getMock ('Symfony\Component\HttpKernel\KernelInterface ' );
72+ $ kernel
73+ ->expects ($ this ->any ())
74+ ->method ('getBundles ' )
75+ ->will ($ this ->returnValue (array ($ bundle )))
76+ ;
77+
78+ $ application = new Application ($ kernel );
79+
80+ $ command = new Command ('example ' );
81+ $ application ->add ($ command );
82+
83+ $ this ->assertSame ($ command , $ application ->get ('example ' ));
84+ }
85+
86+ public function testBundleCommandCanBeFound ()
87+ {
88+ $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
89+ $ bundle ->expects ($ this ->once ())->method ('registerCommands ' );
90+
91+ $ kernel = $ this ->getMock ('Symfony\Component\HttpKernel\KernelInterface ' );
92+ $ kernel
93+ ->expects ($ this ->any ())
94+ ->method ('getBundles ' )
95+ ->will ($ this ->returnValue (array ($ bundle )))
96+ ;
97+
98+ $ application = new Application ($ kernel );
99+
100+ $ command = new Command ('example ' );
101+ $ application ->add ($ command );
102+
103+ $ this ->assertSame ($ command , $ application ->find ('example ' ));
104+ }
105+
106+ public function testBundleCommandCanBeFoundByAlias ()
107+ {
108+ $ bundle = $ this ->getMock ('Symfony\Component\HttpKernel\Bundle\Bundle ' );
109+ $ bundle ->expects ($ this ->once ())->method ('registerCommands ' );
110+
111+ $ kernel = $ this ->getMock ('Symfony\Component\HttpKernel\KernelInterface ' );
112+ $ kernel
113+ ->expects ($ this ->any ())
114+ ->method ('getBundles ' )
115+ ->will ($ this ->returnValue (array ($ bundle )))
116+ ;
117+
118+ $ application = new Application ($ kernel );
119+
120+ $ command = new Command ('example ' );
121+ $ command ->setAliases (array ('alias ' ));
122+ $ application ->add ($ command );
123+
124+ $ this ->assertSame ($ command , $ application ->find ('alias ' ));
41125 }
42126
43127 public function testBundleCommandsHaveRightContainer ()
0 commit comments