8000 More cleanups and fixes · symfony/symfony@75fd4ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 75fd4ce

Browse files
More cleanups and fixes
1 parent 48afd70 commit 75fd4ce

File tree

26 files changed

+112
-110
lines changed

26 files changed

+112
-110
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,34 @@
1919
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag;
2020
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
2121
use Symfony\Component\Form\Form;
22+
use Symfony\Component\Form\FormBuilderInterface;
2223
use Symfony\Component\Form\FormConfigInterface;
24+
use Symfony\Component\Form\FormFactoryInterface;
2325
use Symfony\Component\HttpFoundation\BinaryFileResponse;
26+
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
2427
use Symfony\Component\HttpFoundation\File\File;
2528
use Symfony\Component\HttpFoundation\JsonResponse;
29+
use Symfony\Component\HttpFoundation\RedirectResponse;
2630
use Symfony\Component\HttpFoundation\Request;
2731
use Symfony\Component\HttpFoundation\RequestStack;
2832
use Symfony\Component\HttpFoundation\Response;
2933
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
3034
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
35+
use Symfony\Component\HttpFoundation\Session\Session;
36+
use Symfony\Component\HttpFoundation\StreamedResponse;
37+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
38+
use Symfony\Component\HttpKernel\HttpKernelInterface;
3139
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
40+
use 10000 Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
3241
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
42+
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
43+
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
3344
use Symfony\Component\Security\Core\User\User;
45+
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
3446
use Symfony\Component\Serializer\SerializerInterface;
47+
use Symfony\Component\Routing\RouterInterface;
3548
use Symfony\Component\WebLink\Link;
49+
use Twig\Environment;
3650

3751
class AbstractControllerTest extends TestCase
3852
{
@@ -103,7 +117,7 @@ public function testForward()
103117
$requestStack = new RequestStack();
104118
$requestStack->push($request);
105119

106-
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock();
120+
$kernel = $this->createMock(HttpKernelInterface::class);
107121
$kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) {
108122
return new Response($request->getRequestFormat().'--'.$request->getLocale());
109123
});
@@ -161,7 +175,7 @@ public function testGetUserWithEmptyContainer()
161175

162176
private function getContainerWithTokenStorage($token = null): Container
163177
{
164-
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage::class)->getMock();
178+
$tokenStorage = $this->createMock(TokenStorage::class);
165179
$tokenStorage
166180
->expects($this->once())
167181
->method('getToken')
@@ -187,7 +201,7 @@ public function testJsonWithSerializer()
187201
{
188202
$container = new Container();
189203

190-
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
204+
$serializer = $this->createMock(SerializerInterface::class);
191205
$serializer
192206
->expects($this->once())
193207
->method('serialize')
@@ -208,7 +222,7 @@ public function testJsonWithSerializerContextOverride()
208222
{
209223
$container = new Container();
210224

211-
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
225+
$serializer = $this->createMock(SerializerInterface::class);
212226
$serializer
213227
->expects($this->once())
214228
->method('serialize')
@@ -230,7 +244,7 @@ public function testJsonWithSerializerContextOverride()
230244
public function testFile()
231245
{
232246
$container = new Container();
233-
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock();
247+
$kernel = $this->createMock(HttpKernelInterface::class);
234248
$container->set('http_kernel', $kernel);
235249

236250
$controller = $this->createController();
@@ -331,7 +345,7 @@ public function testFileFromPathWithCustomizedFileName()
331345

332346
public function testFileWhichDoesNotExist()
333347
{
334-
$this->expectException(\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException::class);
348+
$this->expectException(FileNotFoundException::class);
335349

336350
$controller = $this->createController();
337351

@@ -340,7 +354,7 @@ public function testFileWhichDoesNotExist()
340354

341355
public function testIsGranted()
342356
{
343-
$authorizationChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface::class)->getMock();
357+
$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
344358
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(true);
345359

346360
$container = new Container();
@@ -354,9 +368,9 @@ public function testIsGranted()
354368

355369
public function testdenyAccessUnlessGranted()
356370
{
357-
$this->expectException(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class);
371+
$this->expectException(AccessDeniedException::class);
358372

359-
$authorizationChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface::class)->getMock();
373+
$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
360374
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(false);
361375

362376
$container = new Container();
@@ -370,7 +384,7 @@ public function testdenyAccessUnlessGranted()
370384

371385
public function testRenderViewTwig()
372386
{
373-
$twig = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
387+
$twig = $this->createMock(Environment::class);
374388
$twig->expects($this->once())->method('render')->willReturn('bar');
375389

376390
$container = new Container();
@@ -384,7 +398,7 @@ public function testRenderViewTwig()
384398

385399
public function testRenderTwig()
386400
{
387-
$twig = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
401+
$twig = $this->createMock(Environment::class);
388402
$twig->expects($this->once())->method('render')->willReturn('bar');
389403

390404
$container = new Container();
@@ -398,20 +412,20 @@ public function testRenderTwig()
398412

399413
public function testStreamTwig()
400414
{
401-
$twig = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
415+
$twig = $this->createMock(Environment::class);
402416

403417
$container = new Container();
404418
$container->set('twig', $twig);
405419

406420
$controller = $this->createController();
407421
$controller->setContainer($container);
408422

409-
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\StreamedResponse::class, $controller->stream('foo'));
423+
$this->assertInstanceOf(StreamedResponse::class, $controller->stream('foo'));
410424
}
411425

412426
public function testRedirectToRoute()
413427
{
414-
$router = $this->getMockBuilder(\Symfony\Component\Routing\RouterInterface::class)->getMock();
428+
$router = $this->createMock(RouterInterface::class);
415429
$router->expects($this->once())->method('generate')->willReturn('/foo');
416430

417431
$container = new Container();
@@ -421,7 +435,7 @@ public function testRedirectToRoute()
421435
$controller->setContainer($container);
422436
$response = $controller->redirectToRoute('foo');
423437

424-
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\RedirectResponse::class, $response);
438+
$this->assertInstanceOf(RedirectResponse::class, $response);
425439
$this->assertSame('/foo', $response->getTargetUrl());
426440
$this->assertSame(302, $response->getStatusCode());
427441
}
@@ -432,7 +446,7 @@ public function testRedirectToRoute()
432446
public function testAddFlash()
433447
{
434448
$flashBag = new FlashBag();
435-
$session = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\Session::class)->getMock();
449+
$session = $this->createMock(Session::class);
436450
$session->expects($this->once())->method('getFlashBag')->willReturn($flashBag);
437451

438452
$container = new Container();
@@ -449,12 +463,12 @@ public function testCreateAccessDeniedException()
449463
{
450464
$controller = $this->createController();
451465

452-
$this->assertInstanceOf(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class, $controller->createAccessDeniedException());
466+
$this->assertInstanceOf(AccessDeniedException::class, $controller->createAccessDeniedException());
453467
}
454468

455469
public function testIsCsrfTokenValid()
456470
{
457-
$tokenManager = $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock();
471+
$tokenManager = $this->createMock(CsrfTokenManagerInterface::class);
458472
$tokenManager->expects($this->once())->method('isTokenValid')->willReturn(true);
459473

460474
$container = new Container();
@@ -468,7 +482,7 @@ public function testIsCsrfTokenValid()
468482

469483
public function testGenerateUrl()
470484
{
471-
$router = $this->getMockBuilder(\Symfony\Component\Routing\RouterInterface::class)->getMock();
485+
$router = $this->createMock(RouterInterface::class);
472486
$router->expects($this->once())->method('generate')->willReturn('/foo');
473487

474488
$container = new Container();
@@ -485,7 +499,7 @@ public function testRedirect()
485499
$controller = $this->createController();
486500
$response = $controller->redirect('https://dunglas.fr', 301);
487501

488-
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\RedirectResponse::class, $response);
502+
$this->assertInstanceOf(RedirectResponse::class, $response);
489503
$this->assertSame('https://dunglas.fr', $response->getTargetUrl());
490504
$this->assertSame(301, $response->getStatusCode());
491505
}
@@ -494,14 +508,14 @@ public function testCreateNotFoundException()
494508
{
495509
$controller = $this->createController();
496510

497-
$this->assertInstanceOf(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class, $controller->createNotFoundException());
511+
$this->assertInstanceOf(NotFoundHttpException::class, $controller->createNotFoundException());
498512
}
499513

500514
public function testCreateForm()
501515
{
502-
$form = new Form($this->getMockBuilder(FormConfigInterface::class)->getMock());
516+
$form = new Form($this->createMock(FormConfigInterface::class));
503517

504-
$formFactory = $this->getMockBuilder(\Symfony\Component\Form\FormFactoryInterface::class)->getMock();
518+
$formFactory = $this->createMock(FormFactoryInterface::class);
505519
$formFactory->expects($this->once())->method('create')->willReturn($form);
506520

507521
$container = new Container();
@@ -515,9 +529,9 @@ public function testCreateForm()
515529

516530
public function testCreateFormBuilder()
517531
{
518-
$formBuilder = $this->getMockBuilder(\Symfony\Component\Form\FormBuilderInterface::class)->getMock();
532+
$formBuilder = $this->createMock(FormBuilderInterface::class);
519533

520-
$formFactory = $this->getMockBuilder(\Symfony\Component\Form\FormFactoryInterface::class)->getMock();
534+
$formFactory = $this->createMock(FormFactoryInterface::class);
521535
$formFactory->expects($this->once())->method('createBuilder')->willReturn($formBuilder);
522536

523537
$container = new Container();

src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function testCreateFromChoicesDifferentFilterClosure()
239239

240240
public function testCreateFromLoaderSameLoader()
241241
{
242-
$loader = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
242+
$loader = $this->createMock(ChoiceLoaderInterface::class);
243243
$list = new ArrayChoiceList([]);
244244
$list2 = new ArrayChoiceList([]);
245245

@@ -270,8 +270,8 @@ public function testCreateFromLoaderSameLoaderUseCache()
270270

271271
public function testCreateFromLoaderDifferentLoader()
272272
{
273-
$loader1 = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
274-
$loader2 = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
273+
$loader1 = $this->createMock(ChoiceLoaderInterface::class);
274+
$loader2 = $this->createMock(ChoiceLoaderInterface::class);
275275
$list1 = new ArrayChoiceList([]);
276276
$list2 = new ArrayChoiceList([]);
277277

@@ -289,7 +289,7 @@ public function testCreateFromLoaderDifferentLoader()
289289

290290
public function testCreateFromLoaderSameValueClosure()
291291
{
292-
$loader = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
292+
$loader = $this->createMock(ChoiceLoaderInterface::class);
293293
$type = $this->createMock(FormTypeInterface::class);
294294
$list = new ArrayChoiceList([]);
295295
$list2 = new ArrayChoiceList([]);
@@ -329,7 +329,7 @@ public function testCreateFromLoaderSameValueClosureUseCache()
329329

330330
public function testCreateFromLoaderDifferentValueClosure()
331331
{
332-
$loader = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
332+
$loader = $this->createMock(ChoiceLoaderInterface::class);
333333
$type = $this->createMock(FormTypeInterface::class);
334334
$list1 = new ArrayChoiceList([]);
335335
$list2 = new ArrayChoiceList([]);
@@ -350,7 +350,7 @@ public function testCreateFromLoaderDifferentValueClosure()
350350

351351
public function testCreateFromLoaderSameFilterClosure()
352352
{
353-
$loader = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
353+
$loader = $this->createMock(ChoiceLoaderInterface::class);
354354
$type = $this->createMock(FormTypeInterface::class);
355355
$list = new ArrayChoiceList([]);
356356
$list2 = new ArrayChoiceList([]);
@@ -392,7 +392,7 @@ public function testCreateFromLoaderSameFilterClosureUseCache()
392392

393393
public function testCreateFromLoaderDifferentFilterClosure()
394394
{
395-
$loader = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
395+
$loader = $this->createMock(ChoiceLoaderInterface::class);
396396
$type = $this->createMock(FormTypeInterface::class);
397397
$list1 = new ArrayChoiceList([]);
398398
$list2 = new ArrayChoiceList([]);

src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public function testCreateFromLoaderWithValues()
267267

268268
public function testCreateFromLoaderWithFilter()
269269
{
270-
$loader = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
270+
$loader = $this->createMock(ChoiceLoaderInterface::class);
271271
$filter = function () {};
272272

273273
$list = $this->factory->createListFromLoader($loader, null, $filter);

src/Symfony/Component/Form/Tests/ChoiceList/Factory/PropertyAccessDecoratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function testCreateFromLoaderPropertyPath()
127127

128128
public function testCreateFromLoaderFilterPropertyPath()
129129
{
130-
$loader = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
130+
$loader = $this->createMock(ChoiceLoaderInterface::class);
131131
$filteredChoices = [
132132
'two' => (object) ['property' => 'value 2', 'filter' => true],
133133
];

src/Symfony/Component/Form/Tests/ChoiceList/Loader/FilterChoiceLoaderDecoratorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FilterChoiceLoaderDecoratorTest extends TestCase
1111
{
1212
public function testLoadChoiceList()
1313
{
14-
$decorated = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
14+
$decorated = $this->createMock(ChoiceLoaderInterface::class);
1515
$decorated->expects($this->once())
1616
->method('loadChoiceList')
1717
->willReturn(new ArrayChoiceList(range(1, 4)))
@@ -28,7 +28,7 @@ public function testLoadChoiceList()
2828

2929
public function testLoadChoiceListWithGroupedChoices()
3030
{
31-
$decorated = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
31+
$decorated = $this->createMock(ChoiceLoaderInterface::class);
3232
$decorated->expects($this->once())
3333
->method('loadChoiceList')
3434
->willReturn(new ArrayChoiceList(['units' => range(1, 9), 'tens' => range(10, 90, 10)]))
@@ -54,7 +54,7 @@ public function testLoadValuesForChoices()
5454
{
5555
$evenValues = [1 => '2', 3 => '4'];
5656

57-
$decorated = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
57+
$decorated = $this->createMock(ChoiceLoaderInterface::class);
5858
$decorated->expects($this->never())
5959
->method('loadChoiceList')
6060
;
@@ -78,7 +78,7 @@ public function testLoadChoicesForValues()
7878
$evenChoices = [1 => 2, 3 => 4];
7979
$values = array_map('strval', range(1, 4));
8080

81-
$decorated = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
81+
$decorated = $this->createMock(ChoiceLoaderInterface::class);
8282
$decorated->expects($this->never())
8383
->method('loadChoiceList')
8484
;

src/Symfony/Component/Form/Tests/FormRendererTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Form\FormRenderer;
16+
use Symfony\Component\Form\FormRendererEngineInterface;
1617
use Symfony\Component\Form\FormView;
1718

1819
class FormRendererTest extends TestCase
@@ -38,7 +39,7 @@ public function testRenderARenderedField()
3839
$formView->vars['name'] = 'foo';
3940
$formView->setRendered();
4041

41-
$engine = $this->getMockBuilder(\Symfony\Component\Form\FormRendererEngineInterface::class)->getMock();
42+
$engine = $this->createMock(FormRendererEngineInterface::class);
4243
$renderer = new FormRenderer($engine);
4344
$renderer->searchAndRenderBlock($formView, 'row');
4445
}

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MarshallingSessionHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class MarshallingSessionHandlerTest extends TestCase
3434

3535
protected function setUp(): void
3636
{
37-
$this->marshaller = $this->getMockBuilder(MarshallerInterface::class)->getMock();
38-
$this->handler = $this->getMockBuilder(AbstractSessionHandler::class)->getMock();
37+
$this->marshaller = $this->createMock(MarshallerInterface::class);
38+
$this->handler = $this->createMock(AbstractSessionHandler::class);
3939
}
4040

4141
public function testOpen()

0 commit comments

Comments
 (0)
0