11
11
12
12
namespace Symfony \Bundle \FrameworkBundle \Tests \Controller ;
13
13
14
+ use Psr \Container \ContainerInterface as Psr11ContainerInterface ;
14
15
use Psr \Log \LoggerInterface ;
15
16
use Symfony \Bundle \FrameworkBundle \Controller \ControllerNameParser ;
16
17
use Symfony \Bundle \FrameworkBundle \Controller \ControllerResolver ;
17
18
use Symfony \Component \DependencyInjection \ContainerAwareInterface ;
18
19
use Symfony \Component \DependencyInjection \ContainerInterface ;
19
20
use Symfony \Component \HttpFoundation \Request ;
20
- use Symfony \Component \HttpKernel \Tests \Controller \ControllerResolverTest as BaseControllerResolverTest ;
21
+ use Symfony \Component \HttpKernel \Tests \Controller \ContainerControllerResolverTest ;
21
22
22
- class ControllerResolverTest extends BaseControllerResolverTest
23
+ class ControllerResolverTest extends ContainerControllerResolverTest
23
24
{
24
25
public function testGetControllerOnContainerAware ()
25
26
{
@@ -55,7 +56,7 @@ public function testGetControllerWithBundleNotation()
55
56
->will ($ this ->returnValue ('Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController::testAction ' ))
56
57
;
57
58
58
- $ resolver = $ this ->createControllerResolver (null , $ parser );
59
+ $ resolver = $ this ->createControllerResolver (null , null , $ parser );
59
60
$ request = Request::create ('/ ' );
60
61
$ request ->attributes ->set ('_controller ' , $ shortName );
61
62
@@ -66,110 +67,7 @@ public function testGetControllerWithBundleNotation()
66
67
$ this ->assertSame ('testAction ' , $ controller [1 ]);
67
68
}
68
69
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 )
173
71
{
174
72
if (!$ parser ) {
175
73
$ parser = $ this ->createMockParser ();
@@ -215,14 +113,3 @@ public function __invoke()
215
113
{
216
114
}
217
115
}
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