1111
1212namespace Symfony \Bundle \FrameworkBundle \Tests \Controller ;
1313
14+ use Psr \Container \ContainerInterface as Psr11ContainerInterface ;
1415use Psr \Log \LoggerInterface ;
1516use Symfony \Bundle \FrameworkBundle \Controller \ControllerNameParser ;
1617use Symfony \Bundle \FrameworkBundle \Controller \ControllerResolver ;
1718use Symfony \Component \DependencyInjection \ContainerAwareInterface ;
1819use Symfony \Component \DependencyInjection \ContainerInterface ;
1920use Symfony \Component \HttpFoundation \Request ;
20- use Symfony \Component \HttpKernel \Tests \Controller \ControllerResolverTest as BaseControllerResolverTest ;
21+ use Symfony \Component \HttpKernel \Tests \Controller \ContainerControllerResolverTest ;
2122
22- class ControllerResolverTest extends BaseControllerResolverTest
23+ class ControllerResolverTest extends ContainerControllerResolverTest
2324{
2425 public function testGetControllerOnContainerAware ()
2526 {
@@ -55,7 +56,7 @@ public function testGetControllerWithBundleNotation()
5556 ->will ($ this ->returnValue ('Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController::testAction ' ))
5657 ;
5758
58- $ resolver = $ this ->createControllerResolver (null , $ parser );
59+ $ resolver = $ this ->createControllerResolver (null , null , $ parser );
5960 $ request = Request::create ('/ ' );
6061 $ request ->attributes ->set ('_controller ' , $ shortName );
6162
@@ -66,110 +67,7 @@ public function testGetControllerWithBundleNotation()
6667 $ this ->assertSame ('testAction ' , $ controller [1 ]);
6768 }
6869
69- public function testGetControllerService ()
70- {
71- $ container = $ this ->createMockContainer ();
72- $ container ->expects ($ this ->once ())
73- ->method ('get ' )
74- ->with ('foo ' )
75- ->will ($ this ->returnValue ($ this ))
76- ;
77-
78- $ resolver = $ this ->createControllerResolver (null , null , $ container );
79- $ request = Request::create ('/ ' );
80- $ request ->attributes ->set ('_controller ' , 'foo:controllerMethod1 ' );
81-
82- $ controller = $ resolver ->getController ($ request );
83-
84- $ this ->assertInstanceOf (get_class ($ this ), $ controller [0 ]);
85- $ this ->assertSame ('controllerMethod1 ' , $ controller [1 ]);
86- }
87-
88- public function testGetControllerInvokableService ()
89- {
90- $ invokableController = new InvokableController ('bar ' );
91-
92- $ container = $ this ->createMockContainer ();
93- $ container ->expects ($ this ->once ())
94- ->method ('has ' )
95- ->with ('foo ' )
96- ->will ($ this ->returnValue (true ))
97- ;
98- $ container ->expects ($ this ->once ())
99- ->method ('get ' )
100- ->with ('foo ' )
101- ->will ($ this ->returnValue ($ invokableController ))
102- ;
103-
104- $ resolver = $ this ->createControllerResolver (null , null , $ container );
105- $ request = Request::create ('/ ' );
106- $ request ->attributes ->set ('_controller ' , 'foo ' );
107-
108- $ controller = $ resolver ->getController ($ request );
109-
110- $ this ->assertEquals ($ invokableController , $ controller );
111- }
112-
113- public function testGetControllerInvokableServiceWithClassNameAsName ()
114- {
115- $ invokableController = new InvokableController ('bar ' );
116- $ className = __NAMESPACE__ .'\InvokableController ' ;
117-
118- $ container = $ this ->createMockContainer ();
119- $ container ->expects ($ this ->once ())
120- ->method ('has ' )
121- ->with ($ className )
122- ->will ($ this ->returnValue (true ))
123- ;
124- $ container ->expects ($ this ->once ())
125- ->method ('get ' )
126- ->with ($ className )
127- ->will ($ this ->returnValue ($ invokableController ))
128- ;
129-
130- $ resolver = $ this ->createControllerResolver (null , null , $ container );
131- $ request = Request::create ('/ ' );
132- $ request ->attributes ->set ('_controller ' , $ className );
133-
134- $ controller = $ resolver ->getController ($ request );
135-
136- $ this ->assertEquals ($ invokableController , $ controller );
137- }
138-
139- /**
140- * @dataProvider getUndefinedControllers
141- */
142- public function testGetControllerOnNonUndefinedFunction ($ controller , $ exceptionName = null , $ exceptionMessage = null )
143- {
144- // All this logic needs to be duplicated, since calling parent::testGetControllerOnNonUndefinedFunction will override the expected excetion and not use the regex
145- $ resolver = $ this ->createControllerResolver ();
146- if (method_exists ($ this , 'expectException ' )) {
147- $ this ->expectException ($ exceptionName );
148- $ this ->expectExceptionMessageRegExp ($ exceptionMessage );
149- } else {
150- $ this ->setExpectedExceptionRegExp ($ exceptionName , $ exceptionMessage );
151- }
152-
153- $ request = Request::create ('/ ' );
154- $ request ->attributes ->set ('_controller ' , $ controller );
155- $ resolver ->getController ($ request );
156- }
157-
158- public function getUndefinedControllers ()
159- {
160- return array (
161- array ('foo ' , '\LogicException ' , '/Unable to parse the controller name "foo"\./ ' ),
162- array ('oof::bar ' , '\InvalidArgumentException ' , '/Class "oof" does not exist\./ ' ),
163- array ('stdClass ' , '\LogicException ' , '/Unable to parse the controller name "stdClass"\./ ' ),
164- array (
165- 'Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest::bar ' ,
166- '\InvalidArgumentException ' ,
167- '/.?[cC]ontroller(.*?) for URI "\/" is not callable\.( Expected method(.*) Available methods)?/ ' ,
168- ),
169- );
170- }
171-
172- protected function createControllerResolver (LoggerInterface $ logger = null , ControllerNameParser $ parser = null , ContainerInterface $ container = null )
70+ protected function createControllerResolver (LoggerInterface $ logger = null , Psr11ContainerInterface $ container = null , ControllerNameParser $ parser = null )
17371 {
17472 if (!$ parser ) {
17573 $ parser = $ this ->createMockParser ();
@@ -215,14 +113,3 @@ public function __invoke()
215113 {
216114 }
217115}
218-
219- class InvokableController
220- {
221- public function __construct ($ bar ) // mandatory argument to prevent automatic instantiation
222- {
223- }
224-
225- public function __invoke ()
226- {
227- }
228- }
0 commit comments