19
19
use Symfony \Component \DependencyInjection \ParameterBag \ContainerBag ;
20
20
use Symfony \Component \DependencyInjection \ParameterBag \FrozenParameterBag ;
21
21
use Symfony \Component \Form \Form ;
22
+ use Symfony \Component \Form \FormBuilderInterface ;
22
23
use Symfony \Component \Form \FormConfigInterface ;
24
+ use Symfony \Component \Form \FormFactoryInterface ;
23
25
use Symfony \Component \Form \FormInterface ;
24
26
use Symfony \Component \Form \FormView ;
25
27
use Symfony \Component \HttpFoundation \BinaryFileResponse ;
28
+ use Symfony \Component \HttpFoundation \File \Exception \FileNotFoundException ;
26
29
use Symfony \Component \HttpFoundation \File \File ;
27
30
use Symfony \Component \HttpFoundation \JsonResponse ;
31
+ use Symfony \Component \HttpFoundation \RedirectResponse ;
28
32
use Symfony \Component \HttpFoundation \Request ;
29
33
use Symfony \Component \HttpFoundation \RequestStack ;
30
34
use Symfony \Component \HttpFoundation \Response ;
31
35
use Symfony \Component \HttpFoundation \ResponseHeaderBag ;
32
36
use Symfony \Component \HttpFoundation \Session \Flash \FlashBag ;
37
+ use Symfony \Component \HttpFoundation \Session \Session ;
38
+ use Symfony \Component \HttpFoundation \StreamedResponse ;
39
+ use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
40
+ use Symfony \Component \HttpKernel \HttpKernelInterface ;
33
41
use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
42
+ use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorage ;
34
43
use Symfony \Component \Security \Core \Authentication \Token \UsernamePasswordToken ;
44
+ use Symfony \Component \Security \Core \Authorization \AuthorizationCheckerInterface ;
45
+ use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
35
46
use Symfony \Component \Security \Core \User \User ;
47
+ use Symfony \Component \Security \Csrf \CsrfTokenManagerInterface ;
36
48
use Symfony \Component \Serializer \SerializerInterface ;
49
+ use Symfony \Component \Routing \RouterInterface ;
37
50
use Symfony \Component \WebLink \Link ;
38
51
use Twig \Environment ;
39
52
@@ -106,7 +119,7 @@ public function testForward()
106
119
$ requestStack = new RequestStack ();
107
120
$ requestStack ->push ($ request );
108
121
109
- $ kernel = $ this ->getMockBuilder (\ Symfony \ Component \ HttpKernel \ HttpKernelInterface::class)-> getMock ( );
122
+ $ kernel = $ this ->createMock ( HttpKernelInterface::class);
110
123
$ kernel ->expects ($ this ->once ())->method ('handle ' )->willReturnCallback (function (Request $ request ) {
111
124
return new Response ($ request ->getRequestFormat ().'-- ' .$ request ->getLocale ());
112
125
});
@@ -164,7 +177,7 @@ public function testGetUserWithEmptyContainer()
164
177
165
178
private function getContainerWithTokenStorage ($ token = null ): Container
166
179
{
167
- $ tokenStorage = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authentication \ Token \ Storage \ TokenStorage::class)-> getMock ( );
180
+ $ tokenStorage = $ this ->createMock ( TokenStorage::class);
168
181
$ tokenStorage
169
182
->expects ($ this ->once ())
170
183
->method ('getToken ' )
@@ -190,7 +203,7 @@ public function testJsonWithSerializer()
190
203
{
191
204
$ container = new Container ();
192
205
193
- $ serializer = $ this ->getMockBuilder (SerializerInterface::class)-> getMock ( );
206
+ $ serializer = $ this ->createMock (SerializerInterface::class);
194
207
$ serializer
195
208
->expects ($ this ->once ())
196
209
->method ('serialize ' )
@@ -211,7 +224,7 @@ public function testJsonWithSerializerContextOverride()
211
224
{
212
225
$ container = new Container ();
213
226
214
- $ serializer = $ this ->getMockBuilder (SerializerInterface::class)-> getMock ( );
227
+ $ serializer = $ this ->createMock (SerializerInterface::class);
215
228
$ serializer
216
229
->expects ($ this ->once ())
217
230
->method ('serialize ' )
@@ -233,7 +246,7 @@ public function testJsonWithSerializerContextOverride()
233
246
public function testFile ()
234
247
{
235
248
$ container = new Container ();
236
- $ kernel = $ this ->getMockBuilder (\ Symfony \ Component \ HttpKernel \ HttpKernelInterface::class)-> getMock ( );
249
+ $ kernel = $ this ->createMock ( HttpKernelInterface::class);
237
250
$ container ->set ('http_kernel ' , $ kernel );
238
251
239
252
$ controller = $ this ->createController ();
@@ -334,7 +347,7 @@ public function testFileFromPathWithCustomizedFileName()
334
347
335
348
public function testFileWhichDoesNotExist ()
336
349
{
337
- $ this ->expectException (\ Symfony \ Component \ HttpFoundation \ File \ Exception \ FileNotFoundException::class);
350
+ $ this ->expectException (FileNotFoundException::class);
338
351
339
352
$ controller = $ this ->createController ();
340
353
@@ -343,7 +356,7 @@ public function testFileWhichDoesNotExist()
343
356
344
357
public function testIsGranted ()
345
358
{
346
- $ authorizationChecker = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authorization \ AuthorizationCheckerInterface::class)-> getMock ( );
359
+ $ authorizationChecker = $ this ->createMock ( AuthorizationCheckerInterface::class);
347
360
$ authorizationChecker ->expects ($ this ->once ())->method ('isGranted ' )->willReturn (true );
348
361
349
362
$ container = new Container ();
@@ -357,9 +370,9 @@ public function testIsGranted()
357
370
358
371
public function testdenyAccessUnlessGranted ()
359
372
{
360
- $ this ->expectException (\ Symfony \ Component \ Security \ Core \ Exception \ AccessDeniedException::class);
373
+ $ this ->expectException (AccessDeniedException::class);
361
374
362
- $ authorizationChecker = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authorization \ AuthorizationCheckerInterface::class)-> getMock ( );
375
+ $ authorizationChecker = $ this ->createMock ( AuthorizationCheckerInterface::class);
363
376
$ authorizationChecker ->expects ($ this ->once ())->method ('isGranted ' )->willReturn (false );
364
377
365
378
$ container = new Container ();
@@ -373,7 +386,7 @@ public function testdenyAccessUnlessGranted()
373
386
374
387
public function testRenderViewTwig ()
375
388
{
376
- $ twig = $ this ->getMockBuilder (Environment::class)-> disableOriginalConstructor ()-> getMock ( );
389
+ $ twig = $ this ->createMock (Environment::class);
377
390
$ twig ->expects ($ this ->once ())->method ('render ' )->willReturn ('bar ' );
378
391
379
392
$ container = new Container ();
@@ -387,7 +400,7 @@ public function testRenderViewTwig()
387
400
388
401
public function testRenderTwig ()
389
402
{
390
- $ twig = $ this ->getMockBuilder (Environment::class)-> disableOriginalConstructor ()-> getMock ( );
403
+ $ twig = $ this ->createMock (Environment::class);
391
404
$ twig ->expects ($ this ->once ())->method ('render ' )->willReturn ('bar ' );
392
405
393
406
$ container = new Container ();
@@ -401,15 +414,15 @@ public function testRenderTwig()
401
414
402
415
public function testStreamTwig ()
403
416
{
404
- $ twig = $ this ->getMockBuilder (Environment::class)-> disableOriginalConstructor ()-> getMock ( );
417
+ $ twig = $ this ->createMock (Environment::class);
405
418
406
419
$ container = new Container ();
407
420
$ container ->set ('twig ' , $ twig );
408
421
409
422
$ controller = $ this ->createController ();
410
423
$ controller ->setContainer ($ container );
411
424
412
- $ this ->assertInstanceOf (\ Symfony \ Component \ HttpFoundation \ StreamedResponse::class, $ controller ->stream ('foo ' ));
425
+ $ this ->assertInstanceOf (StreamedResponse::class, $ controller ->stream ('foo ' ));
413
426
}
414
427
415
428
public function testRenderFormTwig ()
@@ -460,7 +473,7 @@ public function testRenderInvalidFormTwig()
460
473
461
474
public function testRedirectToRoute ()
462
475
{
463
- $ router = $ this ->getMockBuilder (\ Symfony \ Component \ Routing \ RouterInterface::class)-> getMock ( );
476
+ $ router = $ this ->createMock ( RouterInterface::class);
464
477
$ router ->expects ($ this ->once ())->method ('generate ' )->willReturn ('/foo ' );
465
478
466
479
$ container = new Container ();
@@ -470,7 +483,7 @@ public function testRedirectToRoute()
470
483
$ controller ->setContainer ($ container );
471
484
$ response = $ controller ->redirectToRoute ('foo ' );
472
485
473
- $ this ->assertInstanceOf (\ Symfony \ Component \ HttpFoundation \ RedirectResponse::class, $ response );
486
+ $ this ->assertInstanceOf (RedirectResponse::class, $ response );
474
487
$ this ->assertSame ('/foo ' , $ response ->getTargetUrl ());
475
488
$ this ->assertSame (302 , $ response ->getStatusCode ());
476
489
}
@@ -481,7 +494,7 @@ public function testRedirectToRoute()
481
494
public function testAddFlash ()
482
495
{
483
496
$ flashBag = new FlashBag ();
484
- $ session = $ this ->getMockBuilder (\ Symfony \ Component \ HttpFoundation \ Session \Session ::class)-> getMock ( );
497
+ $ session = $ this ->createMock ( Session::class);
485
498
$ session ->expects ($ this ->once ())->method ('getFlashBag ' )->willReturn ($ flashBag );
486
499
487
500
$ container = new Container ();
@@ -498,12 +511,12 @@ public function testCreateAccessDeniedException()
498
511
{
499
512
$ controller = $ this ->createController ();
500
513
501
- $ this ->assertInstanceOf (\ Symfony \ Component \ Security \ Core \ Exception \ AccessDeniedException::class, $ controller ->createAccessDeniedException ());
514
+ $ this ->assertInstanceOf (AccessDeniedException::class, $ controller ->createAccessDeniedException ());
502
515
}
503
516
504
517
public function testIsCsrfTokenValid ()
505
518
{
506
- $ tokenManager = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Csrf \ CsrfTokenManagerInterface::class)-> getMock ( );
519
+ $ tokenManager = $ this ->createMock ( CsrfTokenManagerInterface::class);
507
520
$ tokenManager ->expects ($ this ->once ())->method ('isTokenValid ' )->willReturn (true );
508
521
509
522
$ container = new Container ();
@@ -517,7 +530,7 @@ public function testIsCsrfTokenValid()
517
530
518
531
public function testGenerateUrl ()
519
532
{
520
- $ router = $ this ->getMockBuilder (\ Symfony \ Component \ Routing \ RouterInterface::class)-> getMock ( );
533
+ $ router = $ this ->createMock ( RouterInterface::class);
521
534
$ router ->expects ($ this ->once ())->method ('generate ' )->willReturn ('/foo ' );
522
535
523
536
$ container = new Container ();
@@ -534,7 +547,7 @@ public function testRedirect()
534
547
$ controller = $ this ->createController ();
535
548
$ response = $ controller ->redirect ('https://dunglas.fr ' , 301 );
536
549
537
- $ this ->assertInstanceOf (\ Symfony \ Component \ HttpFoundation \ RedirectResponse::class, $ response );
550
+ $ this ->assertInstanceOf (RedirectResponse::class, $ response );
538
551
$ this ->assertSame ('https://dunglas.fr ' , $ response ->getTargetUrl ());
539
552
$ this ->assertSame (301 , $ response ->getStatusCode ());
540
553
}
@@ -543,14 +556,14 @@ public function testCreateNotFoundException()
543
556
{
544
557
$ controller = $ this ->createController ();
545
558
546
- $ this ->assertInstanceOf (\ Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException::class, $ controller ->createNotFoundException ());
559
+ $ this ->assertInstanceOf (NotFoundHttpException::class, $ controller ->createNotFoundException ());
547
560
}
548
561
549
562
public function testCreateForm ()
550
563
{
551
- $ form = new Form ($ this ->getMockBuilder (FormConfigInterface::class)-> getMock ( ));
564
+ $ form = new Form ($ this ->createMock (FormConfigInterface::class));
552
565
553
- $ formFactory = $ this ->getMockBuilder (\ Symfony \ Component \ Form \ FormFactoryInterface::class)-> getMock ( );
566
+ $ formFactory = $ this ->createMock ( FormFactoryInterface::class);
554
567
$ formFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ form );
555
568
556
569
$ container = new Container ();
@@ -564,9 +577,9 @@ public function testCreateForm()
564
577
565
578
public function testCreateFormBuilder ()
566
579
{
567
- $ formBuilder = $ this ->getMockBuilder (\ Symfony \ Component \ Form \ FormBuilderInterface::class)-> getMock ( );
580
+ $ formBuilder = $ this ->createMock ( FormBuilderInterface::class);
568
581
569
- $ formFactory = $ this ->getMockBuilder (\ Symfony \ Component \ Form \ FormFactoryInterface::class)-> getMock ( );
582
+ $ formFactory = $ this ->createMock ( FormFactoryInterface::class);
570
583
$ formFactory ->expects ($ this ->once ())->method ('createBuilder ' )->willReturn ($ formBuilder );
571
584
572
585
$ container = new Container ();
0 commit comments