8000 do not use mocks in tests when not necessary · symfony/symfony@1f76255 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f76255

Browse files
committed
do not use mocks in tests when not necessary
1 parent a90648c commit 1f76255

24 files changed

+462
-756
lines changed

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
namespace Symfony\Component\Form\Tests;
1313

14-
use PHPUnit\Framework\MockObject\MockObject;
1514
use PHPUnit\Framework\TestCase;
1615
use Symfony\Component\EventDispatcher\EventDispatcher;
1716
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
18-
use Symfony\Component\Form\DataMapperInterface;
19-
use Symfony\Component\Form\DataTransformerInterface;
2017
use Symfony\Component\Form\FormBuilder;
18+
use Symfony\Component\Form\FormFactory;
2119
use Symfony\Component\Form\FormFactoryInterface;
2220
use Symfony\Component\Form\FormInterface;
21+
use Symfony\Component\Form\FormRegistry;
22+
use Symfony\Component\Form\ResolvedFormTypeFactory;
2323

2424
abstract class AbstractFormTest extends TestCase
2525
{
@@ -29,7 +29,7 @@ abstract class AbstractFormTest extends TestCase
2929
protected $dispatcher;
3030

3131
/**
32-
* @var MockObject&FormFactoryInterface
32+
* @var FormFactoryInterface
3333
*/
3434
protected $factory;
3535

@@ -41,7 +41,7 @@ abstract class AbstractFormTest extends TestCase
4141
protected function setUp(): void
4242
{
4343
$this->dispatcher = new EventDispatcher();
44-
$this->factory = $this->createMock(FormFactoryInterface::class);
44+
$this->factory = new FormFactory(new FormRegistry([], new ResolvedFormTypeFactory()));
4545
$this->form = $this->createForm();
4646
}
4747

@@ -58,20 +58,4 @@ protected function getBuilder(?string $name = 'name', EventDispatcherInterface $
5858
{
5959
return new FormBuilder($name, $dataClass, $dispatcher ?: $this->dispatcher, $this->factory, $options);
6060
}
61-
62-
/**
63-
* @return MockObject&DataMapperInterface
64-
*/
65-
protected function getDataMapper(): DataMapperInterface
66-
{
67-
return $this->createMock(DataMapperInterface::class);
68-
}
69-
70-
/**
71-
* @return MockObject&DataTransformerInterface
72-
*/
73-
protected function getDataTransformer(): DataTransformerInterface
74-
{
75-
return $this->createMock(DataTransformerInterface::class);
76-
}
7761
}

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
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;
1817
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
1918
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
2019
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
@@ -235,7 +234,7 @@ public function testCreateFromLoaderDifferentValueClosure()
235234
public function testCreateViewSamePreferredChoices()
236235
{
237236
$preferred = ['a'];
238-
$list = $this->createMock(ChoiceListInterface::class);
237+
$list = new ArrayChoiceList([]);
239238
$view = new ChoiceListView();
240239

241240
$this->decoratedFactory->expects($this->once())
@@ -251,7 +250,7 @@ public function testCreateViewDifferentPreferredChoices()
251250
{
252251
$preferred1 = ['a'];
253252
$preferred2 = ['b'];
254-
$list = $this->createMock(ChoiceListInterface::class);
253+
$list = new ArrayChoiceList([]);
255254
$view1 = new ChoiceListView();
256255
$view2 = new ChoiceListView();
257256

@@ -270,7 +269,7 @@ public function testCreateViewDifferentPreferredChoices()
270269
public function testCreateViewSamePreferredChoicesClosure()
271270
{
272271
$preferred = function () {};
273-
$list = $this->createMock(ChoiceListInterface::class);
272+
$list = new ArrayChoiceList([]);
274273
$view = new ChoiceListView();
275274

276275
$this->decoratedFactory->expects($this->once())
@@ -286,7 +285,7 @@ public function testCreateViewDifferentPreferredChoicesClosure()
286285
{
287286
$preferred1 = function () {};
288287
$preferred2 = function () {};
289-
$list = $this->createMock(ChoiceListInterface::class);
288+
$list = new ArrayChoiceList([]);
290289
$view1 = new ChoiceListView();
291290
$view2 = new ChoiceListView();
292291

@@ -305,7 +304,7 @@ public function testCreateViewDifferentPreferredChoicesClosure()
305304
public function testCreateViewSameLabelClosure()
306305
{
307306
$labels = function () {};
308-
$list = $this->createMock(ChoiceListInterface::class);
307+
$list = new ArrayChoiceList([]);
309308
$view = new ChoiceListView();
310309

311310
$this->decoratedFactory->expects($this->once())
@@ -321,7 +320,7 @@ public function testCreateViewDifferentLabelClosure()
321320
{
322321
$labels1 = function () {};
323322
$labels2 = function () {};
324-
$list = $this->createMock(ChoiceListInterface::class);
323+
$list = new ArrayChoiceList([]);
325324
$view1 = new ChoiceListView();
326325
$view2 = new ChoiceListView();
327326

@@ -340,7 +339,7 @@ public function testCreateViewDifferentLabelClosure()
340339
public function testCreateViewSameIndexClosure()
341340
{
342341
$index = function () {};
343-
$list = $this->createMock(ChoiceListInterface::class);
342+
$list = new ArrayChoiceList([]);
344343
$view = new ChoiceListView();
345344

346345
$this->decoratedFactory->expects($this->once())
@@ -356,7 +355,7 @@ public function testCreateViewDifferentIndexClosure()
356355
{
357356
$index1 = function () {};
358357
$index2 = function () {};
359-
$list = $this->createMock(ChoiceListInterface::class);
358+
$list = new ArrayChoiceList([]);
360359
$view1 = new ChoiceListView();
361360
$view2 = new ChoiceListView();
362361

@@ -375,7 +374,7 @@ public function testCreateViewDifferentIndexClosure()
375374
public function testCreateViewSameGroupByClosure()
376375
{
377376
$groupBy = function () {};
378-
$list = $this->createMock(ChoiceListInterface::class);
377+
$list = new ArrayChoiceList([]);
379378
$view = new ChoiceListView();
380379

381380
$this->decoratedFactory->expects($this->once())
@@ -391,7 +390,7 @@ public function testCreateViewDifferentGroupByClosure()
391390
{
392391
$groupBy1 = function () {};
393392
$groupBy2 = function () {};
394-
$list = $this->createMock(ChoiceListInterface::class);
393+
$list = new ArrayChoiceList([]);
395394
$view1 = new ChoiceListView();
396395
$view2 = new ChoiceListView();
397396

@@ -410,7 +409,7 @@ public function testCreateViewDifferentGroupByClosure()
410409
public function testCreateViewSameAttributes()
411410
{
412411
$attr = ['class' => 'foobar'];
413-
$list = $this->createMock(ChoiceListInterface::class);
412+
$list = new ArrayChoiceList([]);
414413
$view = new ChoiceListView();
415414

416415
$this->decoratedFactory->expects($this->once())
@@ -426,7 +425,7 @@ public function testCreateViewDifferentAttributes()
426425
{
427426
$attr1 = ['class' => 'foobar1'];
428427
$attr2 = ['class' => 'foobar2'];
429-
$list = $this->createMock(ChoiceListInterface::class);
428+
$list = new ArrayChoiceList([]);
430429
$view1 = new ChoiceListView();
431430
$view2 = new ChoiceListView();
432431

@@ -445,7 +444,7 @@ public function testCreateViewDifferentAttributes()
445444
public function testCreateViewSameAttributesClosure()
446445
{
447446
$attr = function () {};
448-
$list = $this->createMock(ChoiceListInterface::class);
447+
$list = new ArrayChoiceList([]);
449448
$view = new ChoiceListView();
450449

451450
$this->decoratedFactory->expects($this->once())
@@ -461,7 +460,7 @@ public function testCreateViewDifferentAttributesClosure()
461460
{
462461
$attr1 = function () {};
463462
$attr2 = function () {};
464-
$list = $this->createMock(ChoiceListInterface::class);
463+
$list = new ArrayChoiceList([]);
465464
$view1 = new ChoiceListView();
466465
$view2 = new ChoiceListView();
467466

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
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;
1817
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
1918
use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
2019
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
@@ -130,7 +129,7 @@ public function testCreateFromLoaderPropertyPathInstance()
130129

131130
public function testCreateViewPreferredChoicesAsPropertyPath()
132131
{
133-
$list = $this->createMock(ChoiceListInterface::class);
132+
$list = new ArrayChoiceList([]);
134133

135134
$this->decoratedFactory->expects($this->once())
136135
->method('createView')
@@ -144,7 +143,7 @@ public function testCreateViewPreferredChoicesAsPropertyPath()
144143

145144
public function testCreateViewPreferredChoicesAsPropertyPathInstance()
146145
{
147-
$list = $this->createMock(ChoiceListInterface::class);
146+
$list = new ArrayChoiceList([]);
148147

149148
$this->decoratedFactory->expects($this->once())
150149
->method('createView')
@@ -159,7 +158,7 @@ public function testCreateViewPreferredChoicesAsPropertyPathInstance()
159158
// https://github.com/symfony/symfony/issues/5494
160159
public function testCreateViewAssumeNullIfPreferredChoicesPropertyPathUnreadable()
161160
{
162-
$list = $this->createMock(ChoiceListInterface::class);
161+
$list = new ArrayChoiceList([]);
163162

164163
$this->decoratedFactory->expects($this->once())
165164
->method('createView')
@@ -173,7 +172,7 @@ public function testCreateViewAssumeNullIfPreferredChoicesPropertyPathUnreadable
173172

174173
public function testCreateViewLabelsAsPropertyPath()
175174
{
176-
$list = $this->createMock(ChoiceListInterface::class);
175+
$list = new ArrayChoiceList([]);
177176

178177
$this->decoratedFactory->expects($this->once())
179178
->method('createView')
@@ -187,7 +186,7 @@ public function testCreateViewLabelsAsPropertyPath()
187186

188187
public function testCreateViewLabelsAsPropertyPathInstance()
189188
{
190-
$list = $this->createMock(ChoiceListInterface::class);
189+
$list = new ArrayChoiceList([]);
191190

192191
$this->decoratedFactory->expects($this->once())
193192
->method('createView')
@@ -201,7 +200,7 @@ public function testCreateViewLabelsAsPropertyPathInstance()
201200

202201
public function testCreateViewIndicesAsPropertyPath()
203202
{
204-
$list = $this->createMock(ChoiceListInterface::class);
203+
$list = new ArrayChoiceList([]);
205204

206205
$this->decoratedFactory->expects($this->once())
207206
->method('createView')
@@ -215,7 +214,7 @@ public function testCreateViewIndicesAsPropertyPath()
215214

216215
public function testCreateViewIndicesAsPropertyPathInstance()
217216
{
218-
$list = $this->createMock(ChoiceListInterface::class);
217+
$list = new ArrayChoiceList([]);
219218

220219
$this->decoratedFactory->expects($this->once())
221220
->method('createView')
@@ -229,7 +228,7 @@ public function testCreateViewIndicesAsPropertyPathInstance()
229228

230229
public function testCreateViewGroupsAsPropertyPath()
231230
{
232-
$list = $this->createMock(ChoiceListInterface::class);
231+
$list = new ArrayChoiceList([]);
233232

234233
$this->decoratedFactory->expects($this->once())
235234
->method('createView')
@@ -243,7 +242,7 @@ public function testCreateViewGroupsAsPropertyPath()
243242

244243
public function testCreateViewGroupsAsPropertyPathInstance()
245244
{
246-
$list = $this->createMock(ChoiceListInterface::class);
245+
$list = new ArrayChoiceList([]);
247246

248247
$this->decoratedFactory->expects($this->once())
249248
->method('createView')
@@ -258,7 +257,7 @@ public function testCreateViewGroupsAsPropertyPathInstance()
258257
// https://github.com/symfony/symfony/issues/5494
259258
public function testCreateViewAssumeNullIfGroupsPropertyPathUnreadable()
260259
{
261-
$list = $this->createMock(ChoiceListInterface::class);
260+
$list = new ArrayChoiceList([]);
262261

263262
$this->decoratedFactory->expects($this->once())
264263
->method('createView')
@@ -272,7 +271,7 @@ public function testCreateViewAssumeNullIfGroupsPropertyPathUnreadable()
272271

273272
public function testCreateViewAttrAsPropertyPath()
274273
{
275-
$list = $this->createMock(ChoiceListInterface::class);
274+
$list = new ArrayChoiceList([]);
276275

277276
$this->decoratedFactory->expects($this->once())
278277
->method('createView')
@@ -286,7 +285,7 @@ public function testCreateViewAttrAsPropertyPath()
286285

287286
public function testCreateViewAttrAsPropertyPathInstance()
288287
{
289-
$list = $this->createMock(ChoiceListInterface::class);
288+
$list = new ArrayChoiceList([]);
290289

291290
$this->decoratedFactory->expects($this->once())
292291
->method('createView')

0 commit comments

Comments
 (0)
0