Skip to content

Commit bab1af9

Browse files
OskarStarknicolas-grekas
authored andcommitted
Use createMock() and use import instead of FQCN
1 parent 346db57 commit bab1af9

File tree

67 files changed

+449
-333
lines changed

Some content is hidden

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

67 files changed

+449
-333
lines changed

Test/Traits/ValidatorExtensionTrait.php

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

40-
$this->validator = $this->getMockBuilder(ValidatorInterface::class)->getMock();
40+
$this->validator = $this->createMock(ValidatorInterface::class);
4141
$metadata = $this->getMockBuilder(ClassMetadata::class)->setConstructorArgs([''])->setMethods(['addPropertyConstraint'])->getMock();
4242
$this->validator->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata));
4343
$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
@@ -33,7 +33,7 @@ private function doSetUp()
3333
{
3434
parent::setUp();
3535

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

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/AbstractTypeExtensionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Form\Exception\LogicException;
1516
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
1617

1718
class AbstractTypeExtensionTest extends TestCase
@@ -21,7 +22,7 @@ class AbstractTypeExtensionTest extends TestCase
2122
*/
2223
public function testImplementingNeitherGetExtendedTypeNorExtendsTypeThrowsException()
2324
{
24-
$this->expectException(\Symfony\Component\Form\Exception\LogicException::class);
25+
$this->expectException(LogicException::class);
2526
$this->expectExceptionMessage('You need to implement the static getExtendedTypes() method when implementing the "Symfony\Component\Form\FormTypeExtensionInterface" in "Symfony\Component\Form\Tests\TypeExtensionWithoutExtendedTypes".');
2627
$extension = new TypeExtensionWithoutExtendedTypes();
2728
$extension->getExtendedType();

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: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
use PHPUnit\Framework\MockObject\MockObject;
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
17+
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
1718
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
19+
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
20+
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
1821
use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
1922

2023
/**
@@ -34,7 +37,7 @@ class CachingFactoryDecoratorTest extends TestCase
3437

3538
protected function setUp(): void
3639
{
37-
$this->decoratedFactory = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface::class)->getMock();
40+
$this->decoratedFactory = $this->createMock(ChoiceListFactoryInterface::class);
3841
$this->factory = new CachingFactoryDecorator($this->decoratedFactory);
3942
}
4043

@@ -163,7 +166,7 @@ public function testCreateFromChoicesDifferentValueClosure()
163166

164167
public function testCreateFromLoaderSameLoader()
165168
{
166-
$loader = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
169+
$loader = $this->createMock(ChoiceLoaderInterface::class);
167170
$list = new ArrayChoiceList([]);
168171

169172
$this->decoratedFactory->expects($this->once())
@@ -177,8 +180,8 @@ public function testCreateFromLoaderSameLoader()
177180

178181
public function testCreateFromLoaderDifferentLoader()
179182
{
180-
$loader1 = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
181-
$loader2 = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
183+
$loader1 = $this->createMock(ChoiceLoaderInterface::class);
184+
$loader2 = $this->createMock(ChoiceLoaderInterface::class);
182185
$list1 = new ArrayChoiceList([]);
183186
$list2 = new ArrayChoiceList([]);
184187

@@ -196,7 +199,7 @@ public function testCreateFromLoaderDifferentLoader()
196199

197200
public function testCreateFromLoaderSameValueClosure()
198201
{
199-
$loader = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
202+
$loader = $this->createMock(ChoiceLoaderInterface::class);
200203
$list = new ArrayChoiceList([]);
201204
$closure = function () {};
202205

@@ -211,7 +214,7 @@ public function testCreateFromLoaderSameValueClosure()
211214

212215
public function testCreateFromLoaderDifferentValueClosure()
213216
{
214-
$loader = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
217+
$loader = $this->createMock(ChoiceLoaderInterface::class);
215218
$list1 = new ArrayChoiceList([]);
216219
$list2 = new ArrayChoiceList([]);
217220
$closure1 = function () {};
@@ -232,7 +235,7 @@ public function testCreateFromLoaderDifferentValueClosure()
232235
public function testCreateViewSamePreferredChoices()
233236
{
234237
$preferred = ['a'];
235-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
238+
$list = $this->createMock(ChoiceListInterface::class);
236239
$view = new ChoiceListView();
237240

238241
$this->decoratedFactory->expects($this->once())
@@ -248,7 +251,7 @@ public function testCreateViewDifferentPreferredChoices()
248251
{
249252
$preferred1 = ['a'];
250253
$preferred2 = ['b'];
251-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
254+
$list = $this->createMock(ChoiceListInterface::class);
252255
$view1 = new ChoiceListView();
253256
$view2 = new ChoiceListView();
254257

@@ -267,7 +270,7 @@ public function testCreateViewDifferentPreferredChoices()
267270
public function testCreateViewSamePreferredChoicesClosure()
268271
{
269272
$preferred = function () {};
270-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
273+
$list = $this->createMock(ChoiceListInterface::class);
271274
$view = new ChoiceListView();
272275

273276
$this->decoratedFactory->expects($this->once())
@@ -283,7 +286,7 @@ public function testCreateViewDifferentPreferredChoicesClosure()
283286
{
284287
$preferred1 = function () {};
285288
$preferred2 = function () {};
286-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
289+
$list = $this->createMock(ChoiceListInterface::class);
287290
$view1 = new ChoiceListView();
288291
$view2 = new ChoiceListView();
289292

@@ -302,7 +305,7 @@ public function testCreateViewDifferentPreferredChoicesClosure()
302305
public function testCreateViewSameLabelClosure()
303306
{
304307
$labels = function () {};
305-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
308+
$list = $this->createMock(ChoiceListInterface::class);
306309
$view = new ChoiceListView();
307310

308311
$this->decoratedFactory->expects($this->once())
@@ -318,7 +321,7 @@ public function testCreateViewDifferentLabelClosure()
318321
{
319322
$labels1 = function () {};
320323
$labels2 = function () {};
321-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
324+
$list = $this->createMock(ChoiceListInterface::class);
322325
$view1 = new ChoiceListView();
323326
$view2 = new ChoiceListView();
324327

@@ -337,7 +340,7 @@ public function testCreateViewDifferentLabelClosure()
337340
public function testCreateViewSameIndexClosure()
338341
{
339342
$index = function () {};
340-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
343+
$list = $this->createMock(ChoiceListInterface::class);
341344
$view = new ChoiceListView();
342345

343346
$this->decoratedFactory->expects($this->once())
@@ -353,7 +356,7 @@ public function testCreateViewDifferentIndexClosure()
353356
{
354357
$index1 = function () {};
355358
$index2 = function () {};
356-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
359+
$list = $this->createMock(ChoiceListInterface::class);
357360
$view1 = new ChoiceListView();
358361
$view2 = new ChoiceListView();
359362

@@ -372,7 +375,7 @@ public function testCreateViewDifferentIndexClosure()
372375
public function testCreateViewSameGroupByClosure()
373376
{
374377
$groupBy = function () {};
375-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
378+
$list = $this->createMock(ChoiceListInterface::class);
376379
$view = new ChoiceListView();
377380

378381
$this->decoratedFactory->expects($this->once())
@@ -388,7 +391,7 @@ public function testCreateViewDifferentGroupByClosure()
388391
{
389392
$groupBy1 = function () {};
390393
$groupBy2 = function () {};
391-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
394+
$list = $this->createMock(ChoiceListInterface::class);
392395
$view1 = new ChoiceListView();
393396
$view2 = new ChoiceListView();
394397

@@ -407,7 +410,7 @@ public function testCreateViewDifferentGroupByClosure()
407410
public function testCreateViewSameAttributes()
408411
{
409412
$attr = ['class' => 'foobar'];
410-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
413+
$list = $this->createMock(ChoiceListInterface::class);
411414
$view = new ChoiceListView();
412415

413416
$this->decoratedFactory->expects($this->once())
@@ -423,7 +426,7 @@ public function testCreateViewDifferentAttributes()
423426
{
424427
$attr1 = ['class' => 'foobar1'];
425428
$attr2 = ['class' => 'foobar2'];
426-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
429+
$list = $this->createMock(ChoiceListInterface::class);
427430
$view1 = new ChoiceListView();
428431
$view2 = new ChoiceListView();
429432

@@ -442,7 +445,7 @@ public function testCreateViewDifferentAttributes()
442445
public function testCreateViewSameAttributesClosure()
443446
{
444447
$attr = function () {};
445-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
448+
$list = $this->createMock(ChoiceListInterface::class);
446449
$view = new ChoiceListView();
447450

448451
$this->decoratedFactory->expects($this->once())
@@ -458,7 +461,7 @@ public function testCreateViewDifferentAttributesClosure()
458461
{
459462
$attr1 = function () {};
460463
$attr2 = function () {};
461-
$list = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\ChoiceListInterface::class)->getMock();
464+
$list = $this->createMock(ChoiceListInterface::class);
462465
$view1 = new ChoiceListView();
463466
$view2 = new ChoiceListView();
464467

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\View\ChoiceGroupView;
2021
use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
2122
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
@@ -193,7 +194,7 @@ function ($object) { return $object->value; }
193194

194195
public function testCreateFromLoader()
195196
{
196-
$loader = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
197+
$loader = $this->createMock(ChoiceLoaderInterface::class);
197198

198199
$list = $this->factory->createListFromLoader($loader);
199200

@@ -202,7 +203,7 @@ public function testCreateFromLoader()
202203

203204
public function testCreateFromLoaderWithValues()
204205
{
205-
$loader = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
206+
$loader = $this->createMock(ChoiceLoaderInterface::class);
206207

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

0 commit comments

Comments
 (0)