Permalink
Browse files

minor #30108 [Form] replace mocks with real objects in tests (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Form] replace mocks with real objects in tests

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

6ac2550 replace mocks with real objects in tests
  • Loading branch information...
nicolas-grekas committed Feb 8, 2019
2 parents 8f29f56 + 6ac2550 commit db445c499442e3761093b958dbc7ed982d9ca97f
Showing with 435 additions and 523 deletions.
  1. +8 −8 src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php
  2. +7 −15 src/Symfony/Component/Form/Tests/DependencyInjection/FormPassTest.php
  3. +102 −149 src/Symfony/Component/Form/Tests/Extension/Core/DataMapper/PropertyPathMapperTest.php
  4. +5 −4 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php
  5. +3 −1 ...fony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerArrayObjectTest.php
  6. +3 −1 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerArrayTest.php
  7. +3 −1 ...omponent/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerCustomArrayObjectTest.php
  8. +0 −6 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerTest.php
  9. +14 −35 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/ResizeFormListenerTest.php
  10. +4 −3 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php
  11. +11 −12 src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php
  12. +8 −9 src/Symfony/Component/Form/Tests/Extension/Csrf/EventListener/CsrfValidationListenerTest.php
  13. +51 −55 src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php
  14. +1 −1 src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php
  15. +50 −82 src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php
  16. +84 −75 src/Symfony/Component/Form/Tests/Extension/Validator/EventListener/ValidationListenerTest.php
  17. +0 −9 src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php
  18. +25 −9 src/Symfony/Component/Form/Tests/Extension/Validator/Type/UploadValidatorExtensionTest.php
  19. +21 −7 src/Symfony/Component/Form/Tests/Extension/Validator/Util/ServerParamsTest.php
  20. +23 −23 src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php
  21. +5 −6 src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorTypeGuesserTest.php
  22. +6 −11 src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php
  23. +1 −1 src/Symfony/Component/Form/Tests/NativeRequestHandlerTest.php
@@ -200,7 +200,7 @@ public function testMergeParamsAndFiles($method)
$form = $this->createForm('param1', $method, true);
$form->add($this->createForm('field1'));
$form->add($this->createBuilder('field2', false, ['allow_file_upload' => true])->getForm());
$file = $this->getMockFile();
$file = $this->getUploadedFile();
$this->setRequestData($method, [
'param1' => [
@@ -225,7 +225,7 @@ public function testMergeParamsAndFiles($method)
public function testParamTakesPrecedenceOverFile($method)
{
$form = $this->createForm('param1', $method);
$file = $this->getMockFile();
$file = $this->getUploadedFile();
$this->setRequestData($method, [
'param1' => 'DATA',
@@ -247,7 +247,7 @@ public function testSubmitFileIfNoParam($method)
$form = $this->createBuilder('param1', false, ['allow_file_upload' => true])
->setMethod($method)
->getForm();
$file = $this->getMockFile();
$file = $this->getUploadedFile();
$this->setRequestData($method, [
'param1' => null,
@@ -269,14 +269,14 @@ public function testSubmitMultipleFiles($method)
$form = $this->createBuilder('param1', false, ['allow_file_upload' => true])
->setMethod($method)
->getForm();
$file = $this->getMockFile();
$file = $this->getUploadedFile();
$this->setRequestData($method, [
'param1' => null,
], [
'param2' => $this->getMockFile('2'),
'param2' => $this->getUploadedFile('2'),
'param1' => $file,
'param3' => $this->getMockFile('3'),
'param3' => $this->getUploadedFile('3'),
]);
$this->requestHandler->handleRequest($form, $this->request);
@@ -332,7 +332,7 @@ public function getPostMaxSizeFixtures()
public function testUploadedFilesAreAccepted()
{
$this->assertTrue($this->requestHandler->isFileUpload($this->getMockFile()));
$this->assertTrue($this->requestHandler->isFileUpload($this->getUploadedFile()));
}
public function testInvalidFilesAreRejected()
@@ -344,7 +344,7 @@ public function testInvalidFilesAreRejected()
abstract protected function getRequestHandler();
abstract protected function getMockFile($suffix = '');
abstract protected function getUploadedFile($suffix = '');
abstract protected function getInvalidFile();
@@ -19,8 +19,9 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Command\DebugCommand;
use Symfony\Component\Form\DependencyInjection\FormPass;
use Symfony\Component\Form\FormRegistryInterface;
use Symfony\Component\Form\FormRegistry;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -70,8 +71,12 @@ public function testAddTaggedTypesToDebugCommand()
{
$container = $this->createContainerBuilder();
$container->register('form.registry', FormRegistry::class);
$commandDefinition = new Definition(DebugCommand::class, [new Reference('form.registry')]);
$commandDefinition->setPublic(true);
$container->setDefinition('form.extension', $this->createExtensionDefinition());
$container->setDefinition('console.command.form_debug', $this->createDebugCommandDefinition());
$container->setDefinition('console.command.form_debug', $commandDefinition);
$container->register('my.type1', __CLASS__.'_Type1')->addTag('form.type')->setPublic(true);
$container->register('my.type2', __CLASS__.'_Type2')->addTag('form.type')->setPublic(true);
@@ -259,19 +264,6 @@ private function createExtensionDefinition()
return $definition;
}
private function createDebugCommandDefinition()
{
$definition = new Definition('Symfony\Component\Form\Command\DebugCommand');
$definition->setPublic(true);
$definition->setArguments([
$formRegistry = $this->getMockBuilder(FormRegistryInterface::class)->getMock(),
[],
['Symfony\Component\Form\Extension\Core\Type'],
]);
return $definition;
}
private function createContainerBuilder()
{
$container = new ContainerBuilder();
Oops, something went wrong.

0 comments on commit db445c4

Please sign in to comment.