1919use Symfony \Component \DependencyInjection \ParameterBag \ContainerBag ;
2020use Symfony \Component \DependencyInjection \ParameterBag \FrozenParameterBag ;
2121use Symfony \Component \Form \Form ;
22+ use Symfony \Component \Form \FormBuilderInterface ;
2223use Symfony \Component \Form \FormConfigInterface ;
24+ use Symfony \Component \Form \FormFactoryInterface ;
2325use Symfony \Component \Form \FormInterface ;
2426use Symfony \Component \Form \FormView ;
2527use Symfony \Component \HttpFoundation \BinaryFileResponse ;
28+ use Symfony \Component \HttpFoundation \File \Exception \FileNotFoundException ;
2629use Symfony \Component \HttpFoundation \File \File ;
2730use Symfony \Component \HttpFoundation \JsonResponse ;
31+ use Symfony \Component \HttpFoundation \RedirectResponse ;
2832use Symfony \Component \HttpFoundation \Request ;
2933use Symfony \Component \HttpFoundation \RequestStack ;
3034use Symfony \Component \HttpFoundation \Response ;
3135use Symfony \Component \HttpFoundation \ResponseHeaderBag ;
3236use 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 ;
3341use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
42+ use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorage ;
3443use Symfony \Component \Security \Core \Authentication \Token \UsernamePasswordToken ;
44+ use Symfony \Component \Security \Core \Authorization \AuthorizationCheckerInterface ;
45+ use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
3546use Symfony \Component \Security \Core \User \User ;
47+ use Symfony \Component \Security \Csrf \CsrfTokenManagerInterface ;
3648use Symfony \Component \Serializer \SerializerInterface ;
49+ use Symfony \Component \Routing \RouterInterface ;
3750use Symfony \Component \WebLink \Link ;
3851use Twig \Environment ;
3952
@@ -106,7 +119,7 @@ public function testForward()
106119 $ requestStack = new RequestStack ();
107120 $ requestStack ->push ($ request );
108121
109- $ kernel = $ this ->getMockBuilder (\ Symfony \ Component \ HttpKernel \ HttpKernelInterface::class)-> getMock ( );
122+ $ kernel = $ this ->createMock ( HttpKernelInterface::class);
110123 $ kernel ->expects ($ this ->once ())->method ('handle ' )->willReturnCallback (function (Request $ request ) {
111124 return new Response ($ request ->getRequestFormat ().'-- ' .$ request ->getLocale ());
112125 });
@@ -164,7 +177,7 @@ public function testGetUserWithEmptyContainer()
164177
165178 private function getContainerWithTokenStorage ($ token = null ): Container
166179 {
167- $ tokenStorage = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authentication \ Token \ Storage \ TokenStorage::class)-> getMock ( );
180+ $ tokenStorage = $ this ->createMock ( TokenStorage::class);
168181 $ tokenStorage
169182 ->expects ($ this ->once ())
170183 ->method ('getToken ' )
@@ -190,7 +203,7 @@ public function testJsonWithSerializer()
190203 {
191204 $ container = new Container ();
192205
193- $ serializer = $ this ->getMockBuilder (SerializerInterface::class)-> getMock ( );
206+ $ serializer = $ this ->createMock (SerializerInterface::class);
194207 $ serializer
195208 ->expects ($ this ->once ())
196209 ->method ('serialize ' )
@@ -211,7 +224,7 @@ public function testJsonWithSerializerContextOverride()
211224 {
212225 $ container = new Container ();
213226
214- $ serializer = $ this ->getMockBuilder (SerializerInterface::class)-> getMock ( );
227+ $ serializer = $ this ->createMock (SerializerInterface::class);
215228 $ serializer
216229 ->expects ($ this ->once ())
217230 ->method ('serialize ' )
@@ -233,7 +246,7 @@ public function testJsonWithSerializerContextOverride()
233246 public function testFile ()
234247 {
235248 $ container = new Container ();
236- $ kernel = $ this ->getMockBuilder (\ Symfony \ Component \ HttpKernel \ HttpKernelInterface::class)-> getMock ( );
249+ $ kernel = $ this ->createMock ( HttpKernelInterface::class);
237250 $ container ->set ('http_kernel ' , $ kernel );
238251
239252 $ controller = $ this ->createController ();
@@ -334,7 +347,7 @@ public function testFileFromPathWithCustomizedFileName()
334347
335348 public function testFileWhichDoesNotExist ()
336349 {
337- $ this ->expectException (\ Symfony \ Component \ HttpFoundation \ File \ Exception \ FileNotFoundException::class);
350+ $ this ->expectException (FileNotFoundException::class);
338351
339352 $ controller = $ this ->createController ();
340353
@@ -343,7 +356,7 @@ public function testFileWhichDoesNotExist()
343356
344357 public function testIsGranted ()
345358 {
346- $ authorizationChecker = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authorization \ AuthorizationCheckerInterface::class)-> getMock ( );
359+ $ authorizationChecker = $ this ->createMock ( AuthorizationCheckerInterface::class);
347360 $ authorizationChecker ->expects ($ this ->once ())->method ('isGranted ' )->willReturn (true );
348361
349362 $ container = new Container ();
@@ -357,9 +370,9 @@ public function testIsGranted()
357370
358371 public function testdenyAccessUnlessGranted ()
359372 {
360- $ this ->expectException (\ Symfony \ Component \ Security \ Core \ Exception \ AccessDeniedException::class);
373+ $ this ->expectException (AccessDeniedException::class);
361374
362- $ authorizationChecker = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authorization \ AuthorizationCheckerInterface::class)-> getMock ( );
375+ $ authorizationChecker = $ this ->createMock ( AuthorizationCheckerInterface::class);
363376 $ authorizationChecker ->expects ($ this ->once ())->method ('isGranted ' )->willReturn (false );
364377
365378 $ container = new Container ();
@@ -373,7 +386,7 @@ public function testdenyAccessUnlessGranted()
373386
374387 public function testRenderViewTwig ()
375388 {
376- $ twig = $ this ->getMockBuilder (Environment::class)-> disableOriginalConstructor ()-> getMock ( );
389+ $ twig = $ this ->createMock (Environment::class);
377390 $ twig ->expects ($ this ->once ())->method ('render ' )->willReturn ('bar ' );
378391
379392 $ container = new Container ();
@@ -387,7 +400,7 @@ public function testRenderViewTwig()
387400
388401 public function testRenderTwig ()
389402 {
390- $ twig = $ this ->getMockBuilder (Environment::class)-> disableOriginalConstructor ()-> getMock ( );
403+ $ twig = $ this ->createMock (Environment::class);
391404 $ twig ->expects ($ this ->once ())->method ('render ' )->willReturn ('bar ' );
392405
393406 $ container = new Container ();
@@ -401,15 +414,15 @@ public function testRenderTwig()
401414
402415 public function testStreamTwig ()
403416 {
404- $ twig = $ this ->getMockBuilder (Environment::class)-> disableOriginalConstructor ()-> getMock ( );
417+ $ twig = $ this ->createMock (Environment::class);
405418
406419 $ container = new Container ();
407420 $ container ->set ('twig ' , $ twig );
408421
409422 $ controller = $ this ->createController ();
410423 $ controller ->setContainer ($ container );
411424
412- $ this ->assertInstanceOf (\ Symfony \ Component \ HttpFoundation \ StreamedResponse::class, $ controller ->stream ('foo ' ));
425+ $ this ->assertInstanceOf (StreamedResponse::class, $ controller ->stream ('foo ' ));
413426 }
414427
415428 public function testRenderFormTwig ()
@@ -460,7 +473,7 @@ public function testRenderInvalidFormTwig()
460473
461474 public function testRedirectToRoute ()
462475 {
463- $ router = $ this ->getMockBuilder (\ Symfony \ Component \ Routing \ RouterInterface::class)-> getMock ( );
476+ $ router = $ this ->createMock ( RouterInterface::class);
464477 $ router ->expects ($ this ->once ())->method ('generate ' )->willReturn ('/foo ' );
465478
466479 $ container = new Container ();
@@ -470,7 +483,7 @@ public function testRedirectToRoute()
470483 $ controller ->setContainer ($ container );
471484 $ response = $ controller ->redirectToRoute ('foo ' );
472485
473- $ this ->assertInstanceOf (\ Symfony \ Component \ HttpFoundation \ RedirectResponse::class, $ response );
486+ $ this ->assertInstanceOf (RedirectResponse::class, $ response );
474487 $ this ->assertSame ('/foo ' , $ response ->getTargetUrl ());
475488 $ this ->assertSame (302 , $ response ->getStatusCode ());
476489 }
@@ -481,7 +494,7 @@ public function testRedirectToRoute()
481494 public function testAddFlash ()
482495 {
483496 $ flashBag = new FlashBag ();
484- $ session = $ this ->getMockBuilder (\ Symfony \ Component \ HttpFoundation \ Session \Session ::class)-> getMock ( );
497+ $ session = $ this ->createMock ( Session::class);
485498 $ session ->expects ($ this ->once ())->method ('getFlashBag ' )->willReturn ($ flashBag );
486499
487500 $ container = new Container ();
@@ -498,12 +511,12 @@ public function testCreateAccessDeniedException()
498511 {
499512 $ controller = $ this ->createController ();
500513
501- $ this ->assertInstanceOf (\ Symfony \ Component \ Security \ Core \ Exception \ AccessDeniedException::class, $ controller ->createAccessDeniedException ());
514+ $ this ->assertInstanceOf (AccessDeniedException::class, $ controller ->createAccessDeniedException ());
502515 }
503516
504517 public function testIsCsrfTokenValid ()
505518 {
506- $ tokenManager = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Csrf \ CsrfTokenManagerInterface::class)-> getMock ( );
519+ $ tokenManager = $ this ->createMock ( CsrfTokenManagerInterface::class);
507520 $ tokenManager ->expects ($ this ->once ())->method ('isTokenValid ' )->willReturn (true );
508521
509522 $ container = new Container ();
@@ -517,7 +530,7 @@ public function testIsCsrfTokenValid()
517530
518531 public function testGenerateUrl ()
519532 {
520- $ router = $ this ->getMockBuilder (\ Symfony \ Component \ Routing \ RouterInterface::class)-> getMock ( );
533+ $ router = $ this ->createMock ( RouterInterface::class);
521534 $ router ->expects ($ this ->once ())->method ('generate ' )->willReturn ('/foo ' );
522535
523536 $ container = new Container ();
@@ -534,7 +547,7 @@ public function testRedirect()
534547 $ controller = $ this ->createController ();
535548 $ response = $ controller ->redirect ('https://dunglas.fr ' , 301 );
536549
537- $ this ->assertInstanceOf (\ Symfony \ Component \ HttpFoundation \ RedirectResponse::class, $ response );
550+ $ this ->assertInstanceOf (RedirectResponse::class, $ response );
538551 $ this ->assertSame ('https://dunglas.fr ' , $ response ->getTargetUrl ());
539552 $ this ->assertSame (301 , $ response ->getStatusCode ());
540553 }
@@ -543,14 +556,14 @@ public function testCreateNotFoundException()
543556 {
544557 $ controller = $ this ->createController ();
545558
546- $ this ->assertInstanceOf (\ Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException::class, $ controller ->createNotFoundException ());
559+ $ this ->assertInstanceOf (NotFoundHttpException::class, $ controller ->createNotFoundException ());
547560 }
548561
549562 public function testCreateForm ()
550563 {
551- $ form = new Form ($ this ->getMockBuilder (FormConfigInterface::class)-> getMock ( ));
564+ $ form = new Form ($ this ->createMock (FormConfigInterface::class));
552565
553- $ formFactory = $ this ->getMockBuilder (\ Symfony \ Component \ Form \ FormFactoryInterface::class)-> getMock ( );
566+ $ formFactory = $ this ->createMock ( FormFactoryInterface::class);
554567 $ formFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ form );
555568
556569 $ container = new Container ();
@@ -564,9 +577,9 @@ public function testCreateForm()
564577
565578 public function testCreateFormBuilder ()
566579 {
567- $ formBuilder = $ this ->getMockBuilder (\ Symfony \ Component \ Form \ FormBuilderInterface::class)-> getMock ( );
580+ $ formBuilder = $ this ->createMock ( FormBuilderInterface::class);
568581
569- $ formFactory = $ this ->getMockBuilder (\ Symfony \ Component \ Form \ FormFactoryInterface::class)-> getMock ( );
582+ $ formFactory = $ this ->createMock ( FormFactoryInterface::class);
570583 $ formFactory ->expects ($ this ->once ())->method ('createBuilder ' )->willReturn ($ formBuilder );
571584
572585 $ container = new Container ();
0 commit comments