Skip to content

Commit f297910

Browse files
committed
replace mocks with real objects in tests
1 parent b5583f3 commit f297910

23 files changed

+435
-523
lines changed

Tests/AbstractRequestHandlerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function testMergeParamsAndFiles($method)
200200
$form = $this->createForm('param1', $method, true);
201201
$form->add($this->createForm('field1'));
202202
$form->add($this->createBuilder('field2', false, ['allow_file_upload' => true])->getForm());
203-
$file = $this->getMockFile();
203+
$file = $this->getUploadedFile();
204204

205205
$this->setRequestData($method, [
206206
'param1' => [
@@ -225,7 +225,7 @@ public function testMergeParamsAndFiles($method)
225225
public function testParamTakesPrecedenceOverFile($method)
226226
{
227227
$form = $this->createForm('param1', $method);
228-
$file = $this->getMockFile();
228+
$file = $this->getUploadedFile();
229229

230230
$this->setRequestData($method, [
231231
'param1' => 'DATA',
@@ -247,7 +247,7 @@ public function testSubmitFileIfNoParam($method)
247247
$form = $this->createBuilder('param1', false, ['allow_file_upload' => true])
248248
->setMethod($method)
249249
->getForm();
250-
$file = $this->getMockFile();
250+
$file = $this->getUploadedFile();
251251

252252
$this->setRequestData($method, [
253253
'param1' => null,
@@ -269,14 +269,14 @@ public function testSubmitMultipleFiles($method)
269269
$form = $this->createBuilder('param1', false, ['allow_file_upload' => true])
270270
->setMethod($method)
271271
->getForm();
272-
$file = $this->getMockFile();
272+
$file = $this->getUploadedFile();
273273

274274
$this->setRequestData($method, [
275275
'param1' => null,
276276
], [
277-
'param2' => $this->getMockFile('2'),
277+
'param2' => $this->getUploadedFile('2'),
278278
'param1' => $file,
279-
'param3' => $this->getMockFile('3'),
279+
'param3' => $this->getUploadedFile('3'),
280280
]);
281281

282282
$this->requestHandler->handleRequest($form, $this->request);
@@ -332,7 +332,7 @@ public function getPostMaxSizeFixtures()
332332

333333
public function testUploadedFilesAreAccepted()
334334
{
335-
$this->assertTrue($this->requestHandler->isFileUpload($this->getMockFile()));
335+
$this->assertTrue($this->requestHandler->isFileUpload($this->getUploadedFile()));
336336
}
337337

338338
public function testInvalidFilesAreRejected()
@@ -344,7 +344,7 @@ abstract protected function setRequestData($method, $data, $files = []);
344344

345345
abstract protected function getRequestHandler();
346346

347-
abstract protected function getMockFile($suffix = '');
347+
abstract protected function getUploadedFile($suffix = '');
348348

349349
abstract protected function getInvalidFile();
350350

Tests/DependencyInjection/FormPassTest.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
use Symfony\Component\DependencyInjection\Reference;
2020
use Symfony\Component\DependencyInjection\ServiceLocator;
2121
use Symfony\Component\Form\AbstractType;
22+
use Symfony\Component\Form\Command\DebugCommand;
2223
use Symfony\Component\Form\DependencyInjection\FormPass;
23-
use Symfony\Component\Form\FormRegistryInterface;
24+
use Symfony\Component\Form\FormRegistry;
2425

2526
/**
2627
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -70,8 +71,12 @@ public function testAddTaggedTypesToDebugCommand()
7071
{
7172
$container = $this->createContainerBuilder();
7273

74+
$container->register('form.registry', FormRegistry::class);
75+
$commandDefinition = new Definition(DebugCommand::class, [new Reference('form.registry')]);
76+
$commandDefinition->setPublic(true);
77+
7378
$container->setDefinition('form.extension', $this->createExtensionDefinition());
74-
$container->setDefinition('console.command.form_debug', $this->createDebugCommandDefinition());
79+
$container->setDefinition('console.command.form_debug', $commandDefinition);
7580
$container->register('my.type1', __CLASS__.'_Type1')->addTag('form.type')->setPublic(true);
7681
$container->register('my.type2', __CLASS__.'_Type2')->addTag('form.type')->setPublic(true);
7782

@@ -259,19 +264,6 @@ private function createExtensionDefinition()
259264
return $definition;
260265
}
261266

262-
private function createDebugCommandDefinition()
263-
{
264-
$definition = new Definition('Symfony\Component\Form\Command\DebugCommand');
265-
$definition->setPublic(true);
266-
$definition->setArguments([
267-
$formRegistry = $this->getMockBuilder(FormRegistryInterface::class)->getMock(),
268-
[],
269-
['Symfony\Component\Form\Extension\Core\Type'],
270-
]);
271-
272-
return $definition;
273-
}
274-
275267
private function createContainerBuilder()
276268
{
277269
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)