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

Skip to content

Commit e807cbc

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

33 files changed

+755
-1532
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/AbstractRequestHandlerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +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;
21+
use Symfony\Component\Form\FormRegistry;
2222
use Symfony\Component\Form\Forms;
2323
use Symfony\Component\Form\RequestHandlerInterface;
24+
use Symfony\Component\Form\ResolvedFormTypeFactory;
2425
use Symfony\Component\Form\Util\ServerParams;
2526

2627
/**
@@ -417,7 +418,7 @@ protected function createForm($name, $method = null, $compound = false)
417418

418419
protected function createBuilder($name, $compound = false, array $options = [])
419420
{
420-
$builder = new FormBuilder($name, null, new EventDispatcher(), $this->createMock(FormFactoryInterface::class), $options);
421+
$builder = new FormBuilder($name, null, new EventDispatcher(), new FormFactory(new FormRegistry([], new ResolvedFormTypeFactory())), $options);
421422
$builder->setCompound($compound);
422423

423424
if ($compound) {

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,19 @@
1212
namespace Symfony\Component\Form\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
15+
use Symfony\Component\EventDispatcher\EventDispatcher;
1616
use Symfony\Component\Form\ButtonBuilder;
1717
use Symfony\Component\Form\Exception\AlreadySubmittedException;
1818
use Symfony\Component\Form\FormBuilder;
19-
use Symfony\Component\Form\FormFactoryInterface;
19+
use Symfony\Component\Form\FormFactory;
20+
use Symfony\Component\Form\FormRegistry;
21+
use Symfony\Component\Form\ResolvedFormTypeFactory;
2022

2123
/**
2224
* @author Bernhard Schussek <bschussek@gmail.com>
2325
*/
2426
class ButtonTest extends TestCase
2527
{
26-
private $dispatcher;
27-
28-
private $factory;
29-
30-
protected function setUp(): void
31-
{
32-
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
33-
$this->factory = $this->createMock(FormFactoryInterface::class);
34-
}
35-
3628
public function testSetParentOnSubmittedButton()
3729
{
3830
$this->expectException(AlreadySubmittedException::class);
@@ -83,6 +75,6 @@ private function getButtonBuilder($name)
8375

8476
private function getFormBuilder()
8577
{
86-
return new FormBuilder('form', null, $this->dispatcher, $this->factory);
78+
return new FormBuilder('form', null, new EventDispatcher(), new FormFactory(new FormRegistry([], new ResolvedFormTypeFactory())));
8779
}
8880
}

0 commit comments

Comments
 (0)
0