@@ -29,7 +29,7 @@ class DynamicRouterTest extends CmfUnitTestCase
29
29
protected $ context ;
30
30
public $ request ;
31
31
32
- protected $ url = '/foo/bar ' ;
32
+ const URL = '/foo/bar ' ;
33
33
34
34
public function setUp ()
35
35
{
@@ -40,7 +40,7 @@ public function setUp()
40
40
$ this ->enhancer = $ this ->buildMock ('Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface ' , array ('enhance ' ));
41
41
42
42
$ this ->context = $ this ->buildMock ('Symfony\Component\Routing\RequestContext ' );
43
- $ this ->request = Request::create ($ this -> url );
43
+ $ this ->request = Request::create (self :: URL );
44
44
45
45
$ this ->router = new DynamicRouter ($ this ->context , $ this ->matcher , $ this ->generator );
46
46
$ this ->router ->addRouteEnhancer ($ this ->enhancer );
@@ -142,18 +142,21 @@ public function testMatchUrl()
142
142
$ routeDefaults = array ('foo ' => 'bar ' );
143
143
$ this ->matcher ->expects ($ this ->once ())
144
144
->method ('match ' )
145
- ->with ($ this -> url )
145
+ ->with (self :: URL )
146
146
->will ($ this ->returnValue ($ routeDefaults ))
147
147
;
148
148
149
149
$ expected = array ('this ' => 'that ' );
150
+ $ test = $ this ;
150
151
$ this ->enhancer ->expects ($ this ->once ())
151
152
->method ('enhance ' )
152
- ->with ($ this ->equalTo ($ routeDefaults ), $ this ->equalTo ($ this ->request ))
153
+ ->with ($ this ->equalTo ($ routeDefaults ), $ this ->callback (function (Request $ request ) use ($ test ) {
154
+ return DynamicRouterTest::URL === $ request ->server ->get ('REQUEST_URI ' );
155
+ }))
153
156
->will ($ this ->returnValue ($ expected ))
154
157
;
155
158
156
- $ results = $ this ->router ->match ($ this -> url );
159
+ $ results = $ this ->router ->match (self :: URL );
157
160
158
161
$ this ->assertEquals ($ expected , $ results );
159
162
}
@@ -164,15 +167,17 @@ public function testMatchRequestWithUrlMatcher()
164
167
165
168
$ this ->matcher ->expects ($ this ->once ())
166
169
->method ('match ' )
167
- ->with ($ this -> url )
170
+ ->with (self :: URL )
168
171
->will ($ this ->returnValue ($ routeDefaults ))
169
172
;
170
173
171
174
$ expected = array ('this ' => 'that ' );
175
+ $ test = $ this ;
172
176
$ this ->enhancer ->expects ($ this ->once ())
173
177
->method ('enhance ' )
174
- // somehow request object gets confused, check on instance only
175
- ->with ($ this ->equalTo ($ routeDefaults ), $ this ->isInstanceOf ('Symfony\Component\HttpFoundation\Request ' ))
178
+ ->with ($ this ->equalTo ($ routeDefaults ), $ this ->callback (function (Request $ request ) use ($ test ) {
179
+ return DynamicRouterTest::URL === $ request ->server ->get ('REQUEST_URI ' );
180
+ }))
176
181
->will ($ this ->returnValue ($ expected ))
177
182
;
178
183
@@ -195,9 +200,12 @@ public function testMatchRequest()
195
200
;
196
201
197
202
$ expected = array ('this ' => 'that ' );
203
+ $ test = $ this ;
198
204
$ this ->enhancer ->expects ($ this ->once ())
199
205
->method ('enhance ' )
200
- ->with ($ this ->equalTo ($ routeDefaults ), $ this ->equalTo ($ this ->request ))
206
+ ->with ($ this ->equalTo ($ routeDefaults ), $ this ->callback (function (Request $ request ) use ($ test ) {
207
+ return DynamicRouterTest::URL === $ request ->server ->get ('REQUEST_URI ' );
208
+ }))
201
209
->will ($ this ->returnValue ($ expected ))
202
210
;
203
211
@@ -223,7 +231,7 @@ public function testMatchFilter()
223
231
->method ('enhance ' )
224
232
;
225
233
226
- $ router ->match ($ this -> url );
234
+ $ router ->match (self :: URL );
227
235
}
228
236
229
237
/**
@@ -256,7 +264,7 @@ public function testMatchUrlWithRequestMatcher()
256
264
$ matcher = $ this ->buildMock ('Symfony\Component\Routing\Matcher\RequestMatcherInterface ' , array ('matchRequest ' , 'setContext ' , 'getContext ' ));
257
265
$ router = new DynamicRouter ($ this ->context , $ matcher , $ this ->generator );
258
266
259
- $ router ->match ($ this -> url );
267
+ $ router ->match (self :: URL );
260
268
}
261
269
262
270
/**
@@ -301,11 +309,11 @@ public function testEventHandler()
301
309
$ routeDefaults = array ('foo ' => 'bar ' );
302
310
$ this ->matcher ->expects ($ this ->once ())
303
311
->method ('match ' )
304
- ->with ($ this -> url )
312
+ ->with (self :: URL )
305
313
->will ($ this ->returnValue ($ routeDefaults ))
306
314
;
307
315
308
- $ this ->assertEquals ($ routeDefaults , $ router ->match ($ this -> url ));
316
+ $ this ->assertEquals ($ routeDefaults , $ router ->match (self :: URL ));
309
317
}
310
318
311
319
public function testEventHandlerRequest ()
@@ -327,7 +335,7 @@ public function testEventHandlerRequest()
327
335
$ routeDefaults = array ('foo ' => 'bar ' );
328
336
$ this ->matcher ->expects ($ this ->once ())
329
337
->method ('match ' )
330
- ->with ($ this -> url )
338
+ ->with (self :: URL )
331
339
->will ($ this ->returnValue ($ routeDefaults ))
332
340
;
333
341
0 commit comments