18
18
use Symfony \Component \HttpFoundation \RequestStack ;
19
19
use Symfony \Component \HttpFoundation \Response ;
20
20
use Symfony \Component \HttpFoundation \Session \Flash \FlashBag ;
21
+ use Symfony \Component \HttpFoundation \StreamedResponse ;
22
+ use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
21
23
use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
22
24
use Symfony \Component \Security \Core \Authentication \Token \UsernamePasswordToken ;
23
25
use Symfony \Component \Security \Core \User \User ;
@@ -261,44 +263,6 @@ public function testIsCsrfTokenValid()
261
263
262
264
$ this ->assertTrue ($ controller ->isCsrfTokenValid ('foo ' , 'bar ' ));
263
265
}
264
- }
265
-
266
- class TestController extends Controller
267
- {
268
- public function forward ($ controller , array $ path = array (), array $ query = array ())
269
- {
270
- return parent ::forward ($ controller , $ path , $ query );
271
- }
272
-
273
- public function getUser ()
274
- {
275
- return parent ::getUser ();
276
- }
277
-
278
- public function isGranted ($ attributes , $ object = null )
279
- {
280
- return parent ::isGranted ($ attributes , $ object );
281
- }
282
-
283
- public function denyAccessUnlessGranted ($ attributes , $ object = null , $ message = 'Access Denied. ' )
284
- {
285
- parent ::denyAccessUnlessGranted ($ attributes , $ object , $ message );
286
- }
287
-
288
- public function redirectToRoute ($ route , array $ parameters = array (), $ status = 302 )
289
- {
290
- return parent ::redirectToRoute ($ route , $ parameters , $ status );
291
- }
292
-
293
- public function addFlash ($ type , $ message )
294
- {
295
- parent ::addFlash ($ type , $ message );
296
- }
297
-
298
- public function isCsrfTokenValid ($ id , $ token )
299
- {
300
- return parent ::isCsrfTokenValid ($ id , $ token );
301
- }
302
266
303
267
public function testGenerateUrl ()
304
268
{
@@ -308,15 +272,15 @@ public function testGenerateUrl()
308
272
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
309
273
$ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ router ));
310
274
311
- $ controller = new Controller ();
275
+ $ controller = new TestController ();
312
276
$ controller ->setContainer ($ container );
313
277
314
278
$ this ->assertEquals ('/foo ' , $ controller ->generateUrl ('foo ' ));
315
279
}
316
280
317
281
public function testRedirect ()
318
282
{
319
- $ controller = new Controller ();
283
+ $ controller = new TestController ();
320
284
$ response = $ controller ->redirect ('http://dunglas.fr ' , 301 );
321
285
322
286
$ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\RedirectResponse ' , $ response );
@@ -330,9 +294,10 @@ public function testRenderViewTemplating()
330
294
$ templating ->expects ($ this ->once ())->method ('render ' )->willReturn ('bar ' );
331
295
332
296
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
333
- $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
297
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->willReturn (true );
298
+ $ container ->expects ($ this ->at (1 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
334
299
335
- $ controller = new Controller ();
300
+ $ controller = new TestController ();
336
301
$ controller ->setContainer ($ container );
337
302
338
303
$ this ->assertEquals ('bar ' , $ controller ->renderView ('foo ' ));
@@ -344,9 +309,10 @@ public function testRenderTemplating()
344
309
$ templating ->expects ($ this ->once ())->method ('renderResponse ' )->willReturn (new Response ('bar ' ));
345
310
346
311
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
347
- $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
312
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->willReturn (true );
313
+ $ container ->expects ($ this ->at (1 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
348
314
349
- $ controller = new Controller ();
315
+ $ controller = new TestController ();
350
316
$ controller ->setContainer ($ container );
351
317
352
318
$ this ->assertEquals ('bar ' , $ controller ->render ('foo ' )->getContent ());
@@ -357,17 +323,18 @@ public function testStreamTemplating()
357
323
$ templating = $ this ->getMock ('Symfony\Component\Routing\RouterInterface ' );
358
324
359
325
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
360
- $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
326
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->willReturn (true );
327
+ $ container ->expects ($ this ->at (1 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
361
328
362
- $ controller = new Controller ();
329
+ $ controller = new TestController ();
363
330
$ controller ->setContainer ($ container );
364
331
365
332
$ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\StreamedResponse ' , $ controller ->stream ('foo ' ));
366
333
}
367
334
368
335
public function testCreateNotFoundException ()
369
336
{
370
- $ controller = new Controller ();
337
+ $ controller = new TestController ();
371
338
372
339
$ this ->assertInstanceOf ('Symfony\Component\HttpKernel\Exception\NotFoundHttpException ' , $ controller ->createNotFoundException ());
373
340
}
@@ -382,7 +349,7 @@ public function testCreateForm()
382
349
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
383
350
$ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ formFactory ));
384
351
385
- $ controller = new Controller ();
352
+ $ controller = new TestController ();
386
353
$ controller ->setContainer ($ container );
387
354
388
355
$ this ->assertEquals ($ form , $ controller ->createForm ('foo ' ));
@@ -398,7 +365,7 @@ public function testCreateFormBuilder()
398
365
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
399
366
$ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ formFactory ));
400
367
401
- $ controller = new Controller ();
368
+ $ controller = new TestController ();
402
369
$ controller ->setContainer ($ container );
403
370
404
371
$ this ->assertEquals ($ formBuilder , $ controller ->createFormBuilder ('foo ' ));
@@ -412,9 +379,97 @@ public function testGetDoctrine()
412
379
$ container ->expects ($ this ->at (0 ))->method ('has ' )->will ($ this ->returnValue (true ));
413
380
$ container ->expects ($ this ->at (1 ))->method ('get ' )->will ($ this ->returnValue ($ doctrine ));
414
381
415
- $ controller = new Controller ();
382
+ $ controller = new TestController ();
416
383
$ controller ->setContainer ($ container );
417
384
418
385
$ this ->assertEquals ($ doctrine , $ controller ->getDoctrine ());
419
386
}
420
387
}
388
+
389
+ class TestController extends Controller
390
+ {
391
+ public function generateUrl ($ route , $ parameters = array (), $ referenceType = UrlGeneratorInterface::ABSOLUTE_PATH )
392
+ {
393
+ return parent ::generateUrl ($ route , $ parameters , $ referenceType );
394
+ }
395
+
396
+ public function redirect ($ url , $ status = 302 )
397
+ {
398
+ return parent ::redirect ($ url , $ status );
399
+ }
400
+
401
+ public function forward ($ controller , array $ path = array (), array $ query = array ())
402
+ {
403
+ return parent ::forward ($ controller , $ path , $ query );
404
+ }
405
+
406
+ public function getUser ()
407
+ {
408
+ return parent ::getUser ();
409
+ }
410
+
411
+ public function isGranted ($ attributes , $ object = null )
412
+ {
413
+ return parent ::isGranted ($ attributes , $ object );
414
+ }
415
+
416
+ public function denyAccessUnlessGranted ($ attributes , $ object = null , $ message = 'Access Denied. ' )
417
+ {
418
+ parent ::denyAccessUnlessGranted ($ attributes , $ object , $ message );
419
+ }
420
+
421
+ public function redirectToRoute ($ route , array $ parameters = array (), $ status = 302 )
422
+ {
423
+ return parent ::redirectToRoute ($ route , $ parameters , $ status );
424
+ }
425
+
426
+ public function addFlash ($ type , $ message )
427
+ {
428
+ parent ::addFlash ($ type , $ message );
429
+ }
430
+
431
+ public function isCsrfTokenValid ($ id , $ token )
432
+ {
433
+ return parent ::isCsrfTokenValid ($ id , $ token );
434
+ }
435
+
436
+ public function renderView ($ view , array $ parameters = array ())
437
+ {
438
+ return parent ::renderView ($ view , $ parameters );
439
+ }
440
+
441
+ public function render ($ view , array $ parameters = array (), Response $ response = null )
442
+ {
443
+ return parent ::render ($ view , $ parameters , $ response );
444
+ }
445
+
446
+ public function stream ($ view , array $ parameters = array (), StreamedResponse $ response = null )
447
+ {
448
+ return parent ::stream ($ view , $ parameters , $ response );
449
+ }
450
+
451
+ public function createNotFoundException ($ message = 'Not Found ' , \Exception $ previous = null )
452
+ {
453
+ return parent ::createNotFoundException ($ message , $ previous );
454
+ }
455
+
456
+ public function createAccessDeniedException ($ message = 'Access Denied. ' , \Exception $ previous = null )
457
+ {
458
+ return parent ::createAccessDeniedException ($ message , $ previous );
459
+ }
460
+
461
+ public function createForm ($ type , $ data = null , array $ options = array ())
462
+ {
463
+ return parent ::createForm ($ type , $ data , $ options );
464
+ }
465
+
466
+ public function createFormBuilder ($ data = null , array $ options = array ())
467
+ {
468
+ return parent ::createFormBuilder ($ data , $ options );
469
+ }
470
+
471
+ public function getDoctrine ()
472
+ {
473
+ return parent ::getDoctrine ();
474
+ }
475
+ }
0 commit comments