19
19
use Symfony \Component \HttpFoundation \RequestStack ;
20
20
use Symfony \Component \HttpFoundation \Response ;
21
21
use Symfony \Component \HttpFoundation \Session \Flash \FlashBag ;
22
+ use Symfony \Component \HttpFoundation \StreamedResponse ;
23
+ use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
22
24
use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
23
25
use Symfony \Component \Security \Core \Authentication \Token \UsernamePasswordToken ;
24
26
use Symfony \Component \Security \Core \User \User ;
@@ -342,49 +344,6 @@ public function testIsCsrfTokenValid()
342
344
343
345
$ this ->assertTrue ($ controller ->isCsrfTokenValid ('foo ' , 'bar ' ));
344
346
}
345
- }
346
-
347
- class TestController extends Controller
348
- {
349
- public function forward ($ controller , array $ path = array (), array $ query = array ())
350
- {
351
- return parent ::forward ($ controller , $ path , $ query );
352
- }
353
-
354
- public function getUser ()
355
- {
356
- return parent ::getUser ();
357
- }
358
-
359
- public function json ($ data , $ status = 200 , $ headers = array (), $ context = array ())
360
- {
361
- return parent ::json ($ data , $ status , $ headers , $ context );
362
- }
363
-
364
- public function isGranted ($ attributes , $ object = null )
365
- {
366
- return parent ::isGranted ($ attributes , $ object );
367
- }
368
-
369
- public function denyAccessUnlessGranted ($ attributes , $ object = null , $ message = 'Access Denied. ' )
370
- {
371
- parent ::denyAccessUnlessGranted ($ attributes , $ object , $ message );
372
- }
373
-
374
- public function redirectToRoute ($ route , array $ parameters = array (), $ status = 302 )
375
- {
376
- return parent ::redirectToRoute ($ route , $ parameters , $ status );
377
- }
378
-
379
- public function addFlash ($ type , $ message )
380
- {
381
- parent ::addFlash ($ type , $ message );
382
- }
383
-
384
- public function isCsrfTokenValid ($ id , $ token )
385
- {
386
- return parent ::isCsrfTokenValid ($ id , $ token );
387
- }
388
347
389
348
public function testGenerateUrl ()
390
349
{
@@ -394,15 +353,15 @@ public function testGenerateUrl()
394
353
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
395
354
$ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ router ));
396
355
397
- $ controller = new Controller ();
356
+ $ controller = new TestController ();
398
357
$ controller ->setContainer ($ container );
399
358
400
359
$ this ->assertEquals ('/foo ' , $ controller ->generateUrl ('foo ' ));
401
360
}
402
361
403
362
public function testRedirect ()
404
363
{
405
- $ controller = new Controller ();
364
+ $ controller = new TestController ();
406
365
$ response = $ controller ->redirect ('http://dunglas.fr ' , 301 );
407
366
408
367
$ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\RedirectResponse ' , $ response );
@@ -416,9 +375,10 @@ public function testRenderViewTemplating()
416
375
$ templating ->expects ($ this ->once ())->method ('render ' )->willReturn ('bar ' );
417
376
418
377
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
419
- $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
378
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->willReturn (true );
379
+ $ container ->expects ($ this ->at (1 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
420
380
421
- $ controller = new Controller ();
381
+ $ controller = new TestController ();
422
382
$ controller ->setContainer ($ container );
423
383
424
384
$ this ->assertEquals ('bar ' , $ controller ->renderView ('foo ' ));
@@ -430,9 +390,10 @@ public function testRenderTemplating()
430
390
$ templating ->expects ($ this ->once ())->method ('renderResponse ' )->willReturn (new Response ('bar ' ));
431
391
432
392
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
433
- $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
393
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->willReturn (true );
394
+ $ container ->expects ($ this ->at (1 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
434
395
435
- $ controller = new Controller ();
396
+ $ controller = new TestController ();
436
397
$ controller ->setContainer ($ container );
437
398
438
399
$ this ->assertEquals ('bar ' , $ controller ->render ('foo ' )->getContent ());
@@ -443,17 +404,18 @@ public function testStreamTemplating()
443
404
$ templating = $ this ->getMock ('Symfony\Component\Routing\RouterInterface ' );
444
405
445
406
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
446
- $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
407
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->willReturn (true );
408
+ $ container ->expects ($ this ->at (1 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
447
409
448
- $ controller = new Controller ();
410
+ $ controller = new TestController ();
449
411
$ controller ->setContainer ($ container );
450
412
451
413
$ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\StreamedResponse ' , $ controller ->stream ('foo ' ));
452
414
}
453
415
454
416
public function testCreateNotFoundException ()
455
417
{
456
- $ controller = new Controller ();
418
+ $ controller = new TestController ();
457
419
458
420
$ this ->assertInstanceOf ('Symfony\Component\HttpKernel\Exception\NotFoundHttpException ' , $ controller ->createNotFoundException ());
459
421
}
@@ -468,7 +430,7 @@ public function testCreateForm()
468
430
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
469
431
$ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ formFactory ));
470
432
471
- $ controller = new Controller ();
433
+ $ controller = new TestController ();
472
434
$ controller ->setContainer ($ container );
473
435
474
436
$ this ->assertEquals ($ form , $ controller ->createForm ('foo ' ));
@@ -484,7 +446,7 @@ public function testCreateFormBuilder()
484
446
$ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
485
447
$ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ formFactory ));
486
448
487
- $ controller = new Controller ();
449
+ $ controller = new TestController ();
488
450
$ controller ->setContainer ($ container );
489
451
490
452
$ this ->assertEquals ($ formBuilder , $ controller ->createFormBuilder ('foo ' ));
@@ -498,9 +460,102 @@ public function testGetDoctrine()
498
460
$ container ->expects ($ this ->at (0 ))->method ('has ' )->will ($ this ->returnValue (true ));
499
461
$ container ->expects ($ this ->at (1 ))->method ('get ' )->will ($ this ->returnValue ($ doctrine ));
500
462
501
- $ controller = new Controller ();
463
+ $ controller = new TestController ();
502
464
$ controller ->setContainer ($ container );
503
465
504
466
$ this ->assertEquals ($ doctrine , $ controller ->getDoctrine ());
505
467
}
506
468
}
469
+
470
+ class TestController extends Controller
471
+ {
472
+ public function generateUrl ($ route , $ parameters = array (), $ referenceType = UrlGeneratorInterface::ABSOLUTE_PATH )
473
+ {
474
+ return parent ::generateUrl ($ route , $ parameters , $ referenceType );
475
+ }
476
+
477
+ public function redirect ($ url , $ status = 302 )
478
+ {
479
+ return parent ::redirect ($ url , $ status );
480
+ }
481
+
482
+ public function forward ($ controller , array $ path = array (), array $ query = array ())
483
+ {
484
+ return parent ::forward ($ controller , $ path , $ query );
485
+ }
486
+
487
+ public function getUser ()
488
+ {
489
+ return parent ::getUser ();
490
+ }
491
+
492
+ public function json ($ data , $ status = 200 , $ headers = array (), $ context = array ())
493
+ {
494
+ return parent ::json ($ data , $ status , $ headers , $ context );
495
+ }
496
+
497
+ public function isGranted ($ attributes , $ object = null )
498
+ {
499
+ return parent ::isGranted ($ attributes , $ object );
500
+ }
501
+
502
+ public function denyAccessUnlessGranted ($ attributes , $ object = null , $ message = 'Access Denied. ' )
503
+ {
504
+ parent ::denyAccessUnlessGranted ($ attributes , $ object , $ message );
505
+ }
506
+
507
+ public function redirectToRoute ($ route , array $ parameters = array (), $ status = 302 )
508
+ {
509
+ return parent ::redirectToRoute ($ route , $ parameters , $ status );
510
+ }
511
+
512
+ public function addFlash ($ type , $ message )
513
+ {
514
+ parent ::addFlash ($ type , $ message );
515
+ }
516
+
517
+ public function isCsrfTokenValid ($ id , $ token )
518
+ {
519
+ return parent ::isCsrfTokenValid ($ id , $ token );
520
+ }
521
+
522
+ public function renderView ($ view , array $ parameters = array ())
523
+ {
524
+ return parent ::renderView ($ view , $ parameters );
525
+ }
526
+
527
+ public function render ($ view , array $ parameters = array (), Response $ response = null )
528
+ {
529
+ return parent ::render ($ view , $ parameters , $ response );
530
+ }
531
+
532
+ public function stream ($ view , array $ parameters = array (), StreamedResponse $ response = null )
533
+ {
534
+ return parent ::stream ($ view , $ parameters , $ response );
535
+ }
536
+
537
+ public function createNotFoundException ($ message = 'Not Found ' , \Exception $ previous = null )
538
+ {
539
+ return parent ::createNotFoundException ($ message , $ previous );
540
+ }
541
+
542
+ public function createAccessDeniedException ($ message = 'Access Denied. ' , \Exception $ previous = null )
543
+ {
544
+ return parent ::createAccessDeniedException ($ message , $ previous );
545
+ }
546
+
547
+ public function createForm ($ type , $ data = null , array $ options = array ())
548
+ {
549
+ return parent ::createForm ($ type , $ data , $ options );
550
+ }
551
+
552
+ public function createFormBuilder ($ data = null , array $ options = array ())
553
+ {
554
+ return parent ::createFormBuilder ($ data , $ options );
555
+ }
556
+
557
+ public function getDoctrine ()
558
+ {
559
+ return parent ::getDoctrine ();
560
+ }
561
+ }
0 commit comments