Skip to content

Commit 44dcd5f

Browse files
Merge branch '5.1' into 5.2
* 5.1: Use createMock() and use import instead of FQCN
2 parents 1f4d2dd + 52f6639 commit 44dcd5f

File tree

66 files changed

+431
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+431
-319
lines changed

Test/Traits/ValidatorExtensionTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function getValidatorExtension(): ValidatorExtension
3434
throw new \Exception(sprintf('The trait "ValidatorExtensionTrait" can only be added to a class that extends "%s".', TypeTestCase::class));
3535
}
3636

37-
$this->validator = $this->getMockBuilder(ValidatorInterface::class)->getMock();
37+
$this->validator = $this->createMock(ValidatorInterface::class);
3838
$metadata = $this->getMockBuilder(ClassMetadata::class)->setConstructorArgs([''])->setMethods(['addPropertyConstraint'])->getMock();
3939
$this->validator->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata));
4040
$this->validator->expects($this->any())->method('validate')->will($this->returnValue(new ConstraintViolationList()));

Test/TypeTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function setUp(): void
3131
{
3232
parent::setUp();
3333

34-
$this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock();
34+
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
3535
$this->builder = new FormBuilder('', null, $this->dispatcher, $this->factory);
3636
}
3737

Tests/AbstractFormTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\EventDispatcher\EventDispatcher;
1717
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
18+
use Symfony\Component\Form\DataMapperInterface;
19+
use Symfony\Component\Form\DataTransformerInterface;
1820
use Symfony\Component\Form\FormBuilder;
21+
use Symfony\Component\Form\FormFactoryInterface;
1922
use Symfony\Component\Form\FormInterface;
23+
use Symfony\Component\Form\FormValidatorInterface;
2024

2125
abstract class AbstractFormTest extends TestCase
2226
{
@@ -26,7 +30,7 @@ abstract class AbstractFormTest extends TestCase
2630
protected $dispatcher;
2731

2832
/**
29-
* @var \Symfony\Component\Form\FormFactoryInterface
33+
* @var FormFactoryInterface
3034
*/
3135
protected $factory;
3236

@@ -38,7 +42,7 @@ abstract class AbstractFormTest extends TestCase
3842
protected function setUp(): void
3943
{
4044
$this->dispatcher = new EventDispatcher();
41-
$this->factory = $this->getMockBuilder(\Symfony\Component\Form\FormFactoryInterface::class)->getMock();
45+
$this->factory = $this->createMock(FormFactoryInterface::class);
4246
$this->form = $this->createForm();
4347
}
4448

@@ -58,16 +62,16 @@ protected function getBuilder(?string $name = 'name', EventDispatcherInterface $
5862

5963
protected function getDataMapper(): MockObject
6064
{
61-
return $this->getMockBuilder(\Symfony\Component\Form\DataMapperInterface::class)->getMock();
65+
return $this->createMock(DataMapperInterface::class);
6266
}
6367

6468
protected function getDataTransformer(): MockObject
6569
{
66-
return $this->getMockBuilder(\Symfony\Component\Form\DataTransformerInterface::class)->getMock();
70+
return $this->createMock(DataTransformerInterface::class);
6771
}
6872

6973
protected function getFormValidator(): MockObject
7074
{
71-
return $this->getMockBuilder(\Symfony\Component\Form\FormValidatorInterface::class)->getMock();
75+
return $this->createMock(FormValidatorInterface::class);
7276
}
7377
}

Tests/AbstractLayoutTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Form\FormError;
1919
use Symfony\Component\Form\FormView;
2020
use Symfony\Component\Form\Test\FormIntegrationTestCase;
21+
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
2122

2223
abstract class AbstractLayoutTest extends FormIntegrationTestCase
2324
{
@@ -34,7 +35,7 @@ protected function setUp(): void
3435

3536
\Locale::setDefault('en');
3637

37-
$this->csrfTokenManager = $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock();
38+
$this->csrfTokenManager = $this->createMock(CsrfTokenManagerInterface::class);
3839

3940
parent::setUp();
4041
}

Tests/AbstractRequestHandlerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
use Symfony\Component\Form\FormBuilder;
1919
use Symfony\Component\Form\FormError;
2020
use Symfony\Component\Form\FormFactory;
21+
use Symfony\Component\Form\FormFactoryInterface;
2122
use Symfony\Component\Form\Forms;
2223
use Symfony\Component\Form\RequestHandlerInterface;
24+
use Symfony\Component\Form\Util\ServerParams;
2325

2426
/**
2527
* @author Bernhard Schussek <[email protected]>
@@ -42,7 +44,7 @@ abstract class AbstractRequestHandlerTest extends TestCase
4244

4345
protected function setUp(): void
4446
{
45-
$this->serverParams = $this->getMockBuilder(\Symfony\Component\Form\Util\ServerParams::class)->setMethods(['getNormalizedIniPostMaxSize', 'getContentLength'])->getMock();
47+
$this->serverParams = $this->getMockBuilder(ServerParams::class)->setMethods(['getNormalizedIniPostMaxSize', 'getContentLength'])->getMock();
4648
$this->requestHandler = $this->getRequestHandler();
4749
$this->factory = Forms::createFormFactoryBuilder()->getFormFactory();
4850
$this->request = null;
@@ -405,7 +407,7 @@ protected function createForm($name, $method = null, $compound = false)
405407

406408
protected function createBuilder($name, $compound = false, array $options = [])
407409
{
408-
$builder = new FormBuilder($name, null, new EventDispatcher(), $this->getMockBuilder(\Symfony\Component\Form\FormFactoryInterface::class)->getMock(), $options);
410+
$builder = new FormBuilder($name, null, new EventDispatcher(), $this->createMock(FormFactoryInterface::class), $options);
409411
$builder->setCompound($compound);
410412

411413
if ($compound) {

Tests/ButtonTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
namespace Symfony\Component\Form\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1516
use Symfony\Component\Form\ButtonBuilder;
17+
use Symfony\Component\Form\Exception\AlreadySubmittedException;
1618
use Symfony\Component\Form\FormBuilder;
19+
use Symfony\Component\Form\FormFactoryInterface;
1720

1821
/**
1922
* @author Bernhard Schussek <[email protected]>
@@ -26,13 +29,13 @@ class ButtonTest extends TestCase
2629

2730
protected function setUp(): void
2831
{
29-
$this->dispatcher = $this->getMockBuilder(\Symfony\Component\EventDispatcher\EventDispatcherInterface::class)->getMock();
30-
$this->factory = $this->getMockBuilder(\Symfony\Component\Form\FormFactoryInterface::class)->getMock();
32+
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
33+
$this->factory = $this->createMock(FormFactoryInterface::class);
3134
}
3235

3336
public function testSetParentOnSubmittedButton()
3437
{
35-
$this->expectException(\Symfony\Component\Form\Exception\AlreadySubmittedException::class);
38+
$this->expectException(AlreadySubmittedException::class);
3639
$button = $this->getButtonBuilder('button')
3740
->getForm()
3841
;

Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
1717
use Symfony\Component\Form\ChoiceList\ChoiceList;
1818
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
19+
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
20+
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
1921
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
22+
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
2023
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
2124
use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
2225
use Symfony\Component\Form\FormTypeInterface;
@@ -38,7 +41,7 @@ class CachingFactoryDecoratorTest extends TestCase
3841

3942
protected function setUp(): void
4043
{
41-
$this->decoratedFactory = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface::class)->getMock();
44+
$this->decoratedFactory = $this->createMock(ChoiceListFactoryInterface::class);
4245
$this->factory = new CachingFactoryDecorator($this->decoratedFactory);
4346
}
4447

@@ -413,7 +416,7 @@ public function testCreateFromLoaderDifferentFilterClosure()
413416
public function testCreateViewSamePreferredChoices()
414417
{
415418
$preferred = ['a'];
416-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
419+
$list = $this->createMock(ChoiceListInterface::class);
417420
$view = new ChoiceListView();
418421
$view2 = new ChoiceListView();
419422

@@ -447,7 +450,7 @@ public function testCreateViewDifferentPreferredChoices()
447450
{
448451
$preferred1 = ['a'];
449452
$preferred2 = ['b'];
450-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
453+
$list = $this->createMock(ChoiceListInterface::class);
451454
$view1 = new ChoiceListView();
452455
$view2 = new ChoiceListView();
453456

@@ -466,7 +469,7 @@ public function testCreateViewDifferentPreferredChoices()
466469
public function testCreateViewSamePreferredChoicesClosure()
467470
{
468471
$preferred = function () {};
469-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
472+
$list = $this->createMock(ChoiceListInterface::class);
470473
$view = new ChoiceListView();
471474
$view2 = new ChoiceListView();
472475

@@ -500,7 +503,7 @@ public function testCreateViewDifferentPreferredChoicesClosure()
500503
{
501504
$preferred1 = function () {};
502505
$preferred2 = function () {};
503-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
506+
$list = $this->createMock(ChoiceListInterface::class);
504507
$view1 = new ChoiceListView();
505508
$view2 = new ChoiceListView();
506509

@@ -519,7 +522,7 @@ public function testCreateViewDifferentPreferredChoicesClosure()
519522
public function testCreateViewSameLabelClosure()
520523
{
521524
$labels = function () {};
522-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
525+
$list = $this->createMock(ChoiceListInterface::class);
523526
$view = new ChoiceListView();
524527
$view2 = new ChoiceListView();
525528

@@ -553,7 +556,7 @@ public function testCreateViewDifferentLabelClosure()
553556
{
554557
$labels1 = function () {};
555558
$labels2 = function () {};
556-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
559+
$list = $this->createMock(ChoiceListInterface::class);
557560
$view1 = new ChoiceListView();
558561
$view2 = new ChoiceListView();
559562

@@ -572,7 +575,7 @@ public function testCreateViewDifferentLabelClosure()
572575
public function testCreateViewSameIndexClosure()
573576
{
574577
$index = function () {};
575-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
578+
$list = $this->createMock(ChoiceListInterface::class);
576579
$view = new ChoiceListView();
577580
$view2 = new ChoiceListView();
578581

@@ -606,7 +609,7 @@ public function testCreateViewDifferentIndexClosure()
606609
{
607610
$index1 = function () {};
608611
$index2 = function () {};
609-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
612+
$list = $this->createMock(ChoiceListInterface::class);
610613
$view1 = new ChoiceListView();
611614
$view2 = new ChoiceListView();
612615

@@ -625,7 +628,7 @@ public function testCreateViewDifferentIndexClosure()
625628
public function testCreateViewSameGroupByClosure()
626629
{
627630
$groupBy = function () {};
628-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
631+
$list = $this->createMock(ChoiceListInterface::class);
629632
$view = new ChoiceListView();
630633
$view2 = new ChoiceListView();
631634

@@ -659,7 +662,7 @@ public function testCreateViewDifferentGroupByClosure()
659662
{
660663
$groupBy1 = function () {};
661664
$groupBy2 = function () {};
662-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
665+
$list = $this->createMock(ChoiceListInterface::class);
663666
$view1 = new ChoiceListView();
664667
$view2 = new ChoiceListView();
665668

@@ -678,7 +681,7 @@ public function testCreateViewDifferentGroupByClosure()
678681
public function testCreateViewSameAttributes()
679682
{
680683
$attr = ['class' => 'foobar'];
681-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
684+
$list = $this->createMock(ChoiceListInterface::class);
682685
$view = new ChoiceListView();
683686
$view2 = new ChoiceListView();
684687

@@ -711,7 +714,7 @@ public function testCreateViewDifferentAttributes()
711714
{
712715
$attr1 = ['class' => 'foobar1'];
713716
$attr2 = ['class' => 'foobar2'];
714-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
717+
$list = $this->createMock(ChoiceListInterface::class);
715718
$view1 = new ChoiceListView();
716719
$view2 = new ChoiceListView();
717720

@@ -730,7 +733,7 @@ public function testCreateViewDifferentAttributes()
730733
public function testCreateViewSameAttributesClosure()
731734
{
732735
$attr = function () {};
733-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
736+
$list = $this->createMock(ChoiceListInterface::class);
734737
$view = new ChoiceListView();
735738
$view2 = new ChoiceListView();
736739

@@ -763,7 +766,7 @@ public function testCreateViewDifferentAttributesClosure()
763766
{
764767
$attr1 = function () {};
765768
$attr2 = function () {};
766-
$list = $this->getMockBuilder(ChoiceListInterface::class)->getMock();
769+
$list = $this->createMock(ChoiceListInterface::class);
767770
$view1 = new ChoiceListView();
768771
$view2 = new ChoiceListView();
769772

Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
1717
use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;
1818
use Symfony\Component\Form\ChoiceList\LazyChoiceList;
19+
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
1920
use Symfony\Component\Form\ChoiceList\Loader\FilterChoiceLoaderDecorator;
2021
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
2122
use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
@@ -247,7 +248,7 @@ function ($choice) {
247248

248249
public function testCreateFromLoader()
249250
{
250-
$loader = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
251+
$loader = $this->createMock(ChoiceLoaderInterface::class);
251252

252253
$list = $this->factory->createListFromLoader($loader);
253254

@@ -256,7 +257,7 @@ public function testCreateFromLoader()
256257

257258
public function testCreateFromLoaderWithValues()
258259
{
259-
$loader = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
260+
$loader = $this->createMock(ChoiceLoaderInterface::class);
260261

261262
$value = function () {};
262263
$list = $this->factory->createListFromLoader($loader, $value);

0 commit comments

Comments
 (0)