diff --git a/.gitignore b/.gitignore index 7579f74..50b321e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor composer.lock +.phpunit.result.cache diff --git a/composer.json b/composer.json index e663443..cc9e48c 100644 --- a/composer.json +++ b/composer.json @@ -10,18 +10,27 @@ ], "homepage": "https://github.com/symftony/form-handler", "require": { - "php": ">=5.5.9", - "symfony/form": ">=2.8 <4.0" + "php": ">=8.1", + "symfony/form": "^6.1" }, "require-dev": { - "phpunit/phpunit": "^4.0", - "symfony/dependency-injection": ">=2.8", - "symfony/http-kernel": ">=2.8", - "symfony/validator": ">=2.8" + "phpunit/phpunit": "^9.1", + "symfony/dependency-injection": "^6.1", + "symfony/config": "^6.1", + "symfony/http-kernel": "^6.1", + "symfony/serializer": "^6.1", + "phpspec/prophecy": "^1.0@dev", + "phpspec/prophecy-phpunit": "^2.1", + "symfony/translation": "^6.1", + "symfony/contracts": "^3.5@dev", + "symfony/validator": "^6.1" }, "suggest": { - "symfony/validator": ">=2.8", - "symfony/serializer": ">=2.8" + "symfony/dependency-injection": "^6.1", + "symfony/config": "^6.1", + "symfony/http-kernel": "^6.1", + "symfony/serializer": "^6.1", + "symfony/translation": "^6.1" }, "license": "MIT", "authors": [ diff --git a/examples/custom-form-web.php b/examples/custom-form-web.php index f698601..7a3a3be 100644 --- a/examples/custom-form-web.php +++ b/examples/custom-form-web.php @@ -68,7 +68,7 @@
$form->isSubmitted() : = var_export($form->isSubmitted()) ?>
- $form->isValid() : = var_export($form->isValid()) ?>
+ $form->isValid() : = $form->isSubmitted() &&var_export($form->isValid()) ?>
$form->getTransformationFailure() :
getTransformationFailure()): ?>
= $form->getTransformationFailure()->getMessage(); ?>
diff --git a/examples/default-return.php b/examples/default-return.php
index 12e3f36..e0ce0aa 100644
--- a/examples/default-return.php
+++ b/examples/default-return.php
@@ -86,7 +86,7 @@
$form->isSubmitted() : = var_export($form->isSubmitted()) ?>
- $form->isValid() : = var_export($form->isValid()) ?>
+ $form->isValid() : = $form->isSubmitted() && var_export($form->isValid()) ?>
$form->getTransformationFailure() :
getTransformationFailure()): ?>
= $form->getTransformationFailure()->getMessage(); ?>
diff --git a/examples/exception-with-validator.php b/examples/exception-with-validator.php
index 7a6c21e..6b187f3 100644
--- a/examples/exception-with-validator.php
+++ b/examples/exception-with-validator.php
@@ -84,7 +84,7 @@
$form->isSubmitted() : = var_export($form->isSubmitted()) ?>
- $form->isValid() : = var_export($form->isValid()) ?>
+ $form->isValid() : = $form->isSubmitted() && var_export($form->isValid()) ?>
$form->getTransformationFailure() :
getTransformationFailure()): ?>
= $form->getTransformationFailure()->getMessage(); ?>
diff --git a/examples/exception.php b/examples/exception.php
index ee969d6..4b4edb5 100644
--- a/examples/exception.php
+++ b/examples/exception.php
@@ -68,7 +68,7 @@
$form->isSubmitted() : = var_export($form->isSubmitted()) ?>
- $form->isValid() : = var_export($form->isValid()) ?>
+ $form->isValid() : = $form->isSubmitted() && var_export($form->isValid()) ?>
$form->getTransformationFailure() :
getTransformationFailure()): ?>
= $form->getTransformationFailure()->getMessage(); ?>
diff --git a/examples/index.php b/examples/index.php
index 1344f96..ffd4ee8 100644
--- a/examples/index.php
+++ b/examples/index.php
@@ -31,11 +31,11 @@
- Reset form
+ Reset form
$form->isSubmitted() : = var_export($form->isSubmitted()) ?>
- $form->isValid() : = var_export($form->isValid()) ?>
+ $form->isValid() : = $form->isSubmitted() && var_export($form->isValid()) ?>
$form->getData() : = var_export($form->getData()); ?>
$formHandler->handleRequest($form) : = var_export($result); ?>
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 27eb337..efe96c0 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,30 +1,21 @@
-
-
-
-
-
-
-
-
- tests
-
-
-
-
-
- src
-
- src/Exception
- src/*Bundle/Resources
-
-
-
+
+
+
+ src
+
+
+ src/Exception
+ src/*Bundle/Resources
+
+
+
+
+
+
+
+ tests
+
+
diff --git a/src/Exception/FormException.php b/src/Exception/FormException.php
index b6c7b75..0d90148 100644
--- a/src/Exception/FormException.php
+++ b/src/Exception/FormException.php
@@ -1,4 +1,5 @@
form = $form;
parent::__construct($message, $code, $previous);
}
- /**
- * @return FormInterface
- */
- public function getForm()
+ public function getForm(): FormInterface
{
return $this->form;
}
diff --git a/src/Exception/InvalidFormException.php b/src/Exception/InvalidFormException.php
index 8532a4a..dcfcd0c 100644
--- a/src/Exception/InvalidFormException.php
+++ b/src/Exception/InvalidFormException.php
@@ -1,4 +1,5 @@
setDefaults(array(
+ $resolver->setDefaults([
'handler_invalid' => false,
- ));
+ ]);
}
- /**
- * {@inheritdoc}
- */
- public function getExtendedType()
+ public static function getExtendedTypes(): iterable
{
- return 'Symfony\Component\Form\Extension\Core\Type\FormType';
+ return [
+ FormType::class
+ ];
}
}
diff --git a/src/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtension.php b/src/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtension.php
index 839ad83..059ae13 100644
--- a/src/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtension.php
+++ b/src/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtension.php
@@ -1,27 +1,25 @@
setDefaults(array(
+ $resolver->setDefaults([
'handler_not_submitted' => false,
- ));
+ ]);
}
- /**
- * {@inheritdoc}
- */
- public function getExtendedType()
+ public static function getExtendedTypes(): iterable
{
- return 'Symfony\Component\Form\Extension\Core\Type\FormType';
+ return [
+ FormType::class
+ ];
}
}
diff --git a/src/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtension.php b/src/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtension.php
index 320045a..621f26a 100644
--- a/src/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtension.php
+++ b/src/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtension.php
@@ -1,27 +1,25 @@
setDefaults(array(
+ $resolver->setDefaults([
'handler_transformation_failed' => false,
- ));
+ ]);
}
- /**
- * {@inheritdoc}
- */
- public function getExtendedType()
+ public static function getExtendedTypes(): iterable
{
- return 'Symfony\Component\Form\Extension\Core\Type\FormType';
+ return [
+ FormType::class
+ ];
}
}
diff --git a/src/FormBundle/DependencyInjection/FormHandlerExtension.php b/src/FormBundle/DependencyInjection/FormHandlerExtension.php
index 933077f..a6258d5 100644
--- a/src/FormBundle/DependencyInjection/FormHandlerExtension.php
+++ b/src/FormBundle/DependencyInjection/FormHandlerExtension.php
@@ -1,4 +1,5 @@
load('services.yml');
diff --git a/src/FormBundle/FormHandlerBundle.php b/src/FormBundle/FormHandlerBundle.php
index b5e6916..3a51526 100644
--- a/src/FormBundle/FormHandlerBundle.php
+++ b/src/FormBundle/FormHandlerBundle.php
@@ -15,7 +15,7 @@ class FormHandlerBundle extends Bundle
/**
* @param ContainerBuilder $container
*/
- public function build(ContainerBuilder $container)
+ public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new FormHandlerCompilerPass());
}
diff --git a/src/FormBundle/Serializer/Normalizer/FormInvalidNormalizer.php b/src/FormBundle/Serializer/Normalizer/FormInvalidNormalizer.php
index 51ca9ae..6ee830b 100644
--- a/src/FormBundle/Serializer/Normalizer/FormInvalidNormalizer.php
+++ b/src/FormBundle/Serializer/Normalizer/FormInvalidNormalizer.php
@@ -1,5 +1,6 @@
@@ -7,54 +8,43 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
+
namespace Symftony\FormHandler\FormBundle\Serializer\Normalizer;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
-use Symfony\Component\Translation\TranslatorInterface;
+use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Normalizes invalid Form instances.
*
* @author Ener-Getick
+ *
* @codeCoverageIgnore
*/
class FormInvalidNormalizer implements NormalizerInterface
{
- /**
- * @var TranslatorInterface
- */
- private $translator;
+ public function __construct(
+ private readonly TranslatorInterface $translator
+ )
+ {
+ }
- /**
- * @param TranslatorInterface $translator
- */
- public function __construct(TranslatorInterface $translator)
+ public function supportsNormalization($data, $format = null): bool
{
- $this->translator = $translator;
+ return $data instanceof FormInterface && $data->isSubmitted() && !$data->isValid();
}
- /**
- * {@inheritdoc}
- */
- public function normalize($object, $format = null, array $context = [])
+ public function normalize($object, $format = null, array $context = []): float|int|bool|\ArrayObject|array|string|null
{
return [
- 'code' => isset($context['status_code']) ? $context['status_code'] : null,
+ 'code' => $context['status_code'] ?? null,
'message' => 'Validation Failed',
'errors' => $this->convertFormToArray($object),
];
}
- /**
- * {@inheritdoc}
- */
- public function supportsNormalization($data, $format = null)
- {
- return $data instanceof FormInterface && $data->isSubmitted() && !$data->isValid();
- }
-
/**
* This code has been taken from JMSSerializer.
*
@@ -62,7 +52,7 @@ public function supportsNormalization($data, $format = null)
*
* @return array
*/
- private function convertFormToArray(FormInterface $data)
+ private function convertFormToArray(FormInterface $data): array
{
$form = $errors = [];
foreach ($data->getErrors() as $error) {
@@ -95,4 +85,5 @@ private function getErrorMessage(FormError $error)
}
return $this->translator->trans($error->getMessageTemplate(), $error->getMessageParameters(), 'validators');
}
+
}
diff --git a/src/FormHandler.php b/src/FormHandler.php
index df33558..1a773a9 100644
--- a/src/FormHandler.php
+++ b/src/FormHandler.php
@@ -1,4 +1,5 @@
formFactory = $formFactory;
}
@@ -31,7 +26,7 @@ public function setFormFactory(FormFactoryInterface $formFactory)
*
* @return FormInterface
*/
- public function createForm($type, $name = null, $data = null, $options = [])
+ public function createForm(string $type, $name = null, $data = null, array $options = []): FormInterface
{
if (null !== $name) {
return $this->formFactory->createNamed($name, $type, $data, $options);
@@ -48,7 +43,7 @@ public function createForm($type, $name = null, $data = null, $options = [])
*
* @throws mixed
*/
- public function handleRequest(FormInterface $form, $request = null)
+ public function handleRequest(FormInterface $form, $request = null): mixed
{
$form->handleRequest($request);
$formConfig = $form->getConfig();
@@ -62,25 +57,7 @@ public function handleRequest(FormInterface $form, $request = null)
return $notSubmitted;
}
- if (!$form->isValid() && $formConfig->hasOption('handler_invalid')) {
- $invalid = $formConfig->getOption('handler_invalid');
- if (true === $invalid) {
- throw new InvalidFormException($form);
- }
-
- return $invalid;
- }
-
- if ($form->getTransformationFailure() && $formConfig->hasOption('handler_transformation_failed')) {
- $failed = $formConfig->getOption('handler_transformation_failed');
- if (true === $failed) {
- throw new TransformationFailedFormException($form);
- }
-
- return $failed;
- }
-
- return $form->getData();
+ return $this->postSubmit($form);
}
/**
@@ -90,7 +67,7 @@ public function handleRequest(FormInterface $form, $request = null)
*
* @return mixed|null
*/
- public function handleData(FormInterface $form, array $data = [], $clearMissing = true)
+ public function handleData(FormInterface $form, array $data = [], bool $clearMissing = true): mixed
{
$formConfig = $form->getConfig();
// Don't auto-submit the form unless at least one field is present.
@@ -105,22 +82,31 @@ public function handleData(FormInterface $form, array $data = [], $clearMissing
$form->submit($data, $clearMissing);
- if (!$form->isValid() && $formConfig->hasOption('handler_invalid')) {
- $invalid = $formConfig->getOption('handler_invalid');
- if (true === $invalid) {
- throw new InvalidFormException($form);
+ return $this->postSubmit($form);
+ }
+
+ private function postSubmit(FormInterface $form,)
+ {
+ $formConfig = $form->getConfig();
+ if ($form->isSubmitted()) {
+ if (!$form->isValid() && $formConfig->hasOption('handler_invalid')) {
+ $invalid = $formConfig->getOption('handler_invalid');
+ if (true === $invalid) {
+ throw new InvalidFormException($form);
+ }
+
+ return $invalid;
}
- return $invalid;
- }
+ $transformationFailure = $form->getTransformationFailure();
+ if ($transformationFailure && $formConfig->hasOption('handler_transformation_failed')) {
+ $failed = $formConfig->getOption('handler_transformation_failed');
+ if (true === $failed) {
+ throw new TransformationFailedFormException($form, 'Transformation form failed.', 0, $transformationFailure);
+ }
- if ($form->getTransformationFailure() && $formConfig->hasOption('handler_transformation_failed')) {
- $failed = $formConfig->getOption('handler_transformation_failed');
- if (true === $failed) {
- throw new TransformationFailedFormException($form);
+ return $failed;
}
-
- return $failed;
}
return $form->getData();
diff --git a/tests/Form/Extension/Invalid/Type/InvalidTypeExtensionTest.php b/tests/Form/Extension/Invalid/Type/InvalidTypeExtensionTest.php
index 5b5b8dc..db7fb70 100644
--- a/tests/Form/Extension/Invalid/Type/InvalidTypeExtensionTest.php
+++ b/tests/Form/Extension/Invalid/Type/InvalidTypeExtensionTest.php
@@ -1,42 +1,44 @@
optionsResolverMock = $this->getMock(OptionsResolver::class);
+ $this->optionsResolverMock = $this->prophesize(OptionsResolver::class);
$this->invalidTypeExtension = new InvalidTypeExtension();
}
public function testConfigureOptions()
{
- $this->optionsResolverMock->expects($this->once())
- ->method('setDefaults')
- ->with($this->equalTo([
+ $this->optionsResolverMock
+ ->setDefaults([
'handler_invalid' => false,
- ]));
+ ])
+ ->willReturn($this->optionsResolverMock->reveal())
+ ->shouldBeCalled();
- $this->invalidTypeExtension->configureOptions($this->optionsResolverMock);
+ $this->invalidTypeExtension->configureOptions($this->optionsResolverMock->reveal());
}
public function testGetExtendedType()
{
- $this->assertEquals('Symfony\Component\Form\Extension\Core\Type\FormType', $this->invalidTypeExtension->getExtendedType());
+ $this->assertEquals([FormType::class], $this->invalidTypeExtension->getExtendedTypes());
}
}
diff --git a/tests/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtensionTest.php b/tests/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtensionTest.php
index e85015f..5cd8d20 100644
--- a/tests/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtensionTest.php
+++ b/tests/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtensionTest.php
@@ -1,42 +1,44 @@
optionsResolverMock = $this->getMock(OptionsResolver::class);
+ $this->optionsResolverMock = $this->prophesize(OptionsResolver::class);
$this->notSubmittedTypeExtension = new NotSubmittedTypeExtension();
}
public function testConfigureOptions()
{
- $this->optionsResolverMock->expects($this->once())
- ->method('setDefaults')
- ->with($this->equalTo([
+ $this->optionsResolverMock
+ ->setDefaults([
'handler_not_submitted' => false,
- ]));
+ ])
+ ->willReturn($this->optionsResolverMock->reveal())
+ ->shouldBeCalled();
- $this->notSubmittedTypeExtension->configureOptions($this->optionsResolverMock);
+ $this->notSubmittedTypeExtension->configureOptions($this->optionsResolverMock->reveal());
}
public function testGetExtendedType()
{
- $this->assertEquals('Symfony\Component\Form\Extension\Core\Type\FormType', $this->notSubmittedTypeExtension->getExtendedType());
+ $this->assertEquals([FormType::class], $this->notSubmittedTypeExtension->getExtendedTypes());
}
}
diff --git a/tests/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtensionTest.php b/tests/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtensionTest.php
index 91e182c..b43e77f 100644
--- a/tests/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtensionTest.php
+++ b/tests/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtensionTest.php
@@ -1,42 +1,44 @@
optionsResolverMock = $this->getMock(OptionsResolver::class);
+ $this->optionsResolverMock = $this->prophesize(OptionsResolver::class);
- $this->transformationFailedTypeExtension = new TransformationFailedTypeExtension();
+ $this->notSubmittedTypeExtension = new TransformationFailedTypeExtension();
}
public function testConfigureOptions()
{
- $this->optionsResolverMock->expects($this->once())
- ->method('setDefaults')
- ->with($this->equalTo([
+ $this->optionsResolverMock
+ ->setDefaults([
'handler_transformation_failed' => false,
- ]));
+ ])
+ ->willReturn($this->optionsResolverMock->reveal())
+ ->shouldBeCalled();
- $this->transformationFailedTypeExtension->configureOptions($this->optionsResolverMock);
+ $this->notSubmittedTypeExtension->configureOptions($this->optionsResolverMock->reveal());
}
public function testGetExtendedType()
{
- $this->assertEquals('Symfony\Component\Form\Extension\Core\Type\FormType', $this->transformationFailedTypeExtension->getExtendedType());
+ $this->assertEquals([FormType::class], $this->notSubmittedTypeExtension->getExtendedTypes());
}
}
diff --git a/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php b/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php
index 6a84254..ccaab08 100644
--- a/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php
+++ b/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php
@@ -1,83 +1,57 @@
containerBuilderMock = $this->getMock(
- ContainerBuilder::class,
- ['findTaggedServiceIds', 'getDefinition', 'hasDefinition']
- );
+ $this->containerBuilder = new ContainerBuilder();
$this->formHandlerCompilerPass = new FormHandlerCompilerPass();
}
- /**
- * @expectedException \LogicException
- * @expectedExceptionMessage Form factory expected for "form.handler" tagged services.
- */
public function testProcessThrowLogicException()
{
- $services = [
- 'my_fake_form_handler1' => [],
- ];
-
- $this->containerBuilderMock->expects($this->once())
- ->method('hasDefinition')
- ->with($this->equalTo('form.factory'))
- ->willReturn(false);
+ $this->expectException(\LogicException::class);
+ $this->expectExceptionMessage('Form factory expected for "form.handler" tagged services.');
- $this->containerBuilderMock->expects($this->once())
- ->method('findTaggedServiceIds')
- ->with($this->equalTo('form.handler'))
- ->willReturn($services);
+ $this->containerBuilder->addDefinitions([
+ 'my_custom_form_handler' => (new Definition())->addTag('form.handler')
+ ]);
- $this->formHandlerCompilerPass->process($this->containerBuilderMock);
+ $this->formHandlerCompilerPass->process($this->containerBuilder);
}
public function testProcess()
{
- $services = [
- 'my_fake_form_handler1' => [],
- ];
-
- $fakeFormHandler1Mock = $this->getMock(Definition::class);
-
- $this->containerBuilderMock->expects($this->once())
- ->method('hasDefinition')
- ->with($this->equalTo('form.factory'))
- ->willReturn(true);
+ $formFactoryDefinition = new Definition();
- $this->containerBuilderMock->expects($this->once())
- ->method('findTaggedServiceIds')
- ->with($this->equalTo('form.handler'))
- ->willReturn($services);
+ $def = new Definition();
+ $def->addTag('form.handler');
- $this->containerBuilderMock->expects($this->exactly(2))
- ->method('getDefinition')
- ->withConsecutive($this->equalTo(['form.factory']), $this->equalTo(['my_fake_form_handler1']))
- ->willReturnOnConsecutiveCalls('my_fake_form_factory_definition', $fakeFormHandler1Mock);
+ $this->containerBuilder->addDefinitions([
+ 'form.factory' => $formFactoryDefinition,
+ 'my_custom_form_handler' => $def,
+ ]);
- $fakeFormHandler1Mock->expects($this->once())
- ->method('addMethodCall')
- ->with($this->equalTo('setFormFactory'), $this->equalTo(['my_fake_form_factory_definition']));
+ $this->formHandlerCompilerPass->process($this->containerBuilder);
- $this->formHandlerCompilerPass->process($this->containerBuilderMock);
+ $this->assertSame([
+ ['setFormFactory', [$formFactoryDefinition]]
+ ], $def->getMethodCalls());
}
}
diff --git a/tests/FormBundle/FormHandlerBundleTest.php b/tests/FormBundle/FormHandlerBundleTest.php
index 6f1b689..38a86fb 100644
--- a/tests/FormBundle/FormHandlerBundleTest.php
+++ b/tests/FormBundle/FormHandlerBundleTest.php
@@ -1,36 +1,38 @@
containerBuilderMock = $this->getMock(ContainerBuilder::class, ['addCompilerPass']);
+ $this->containerBuilder = new ContainerBuilder();
$this->formHandlerBundle = new FormHandlerBundle();
}
public function testBuild()
{
- $this->containerBuilderMock->expects($this->once())
- ->method('addCompilerPass')
- ->with($this->isInstanceOf(FormHandlerCompilerPass::class));
+ $this->formHandlerBundle->build($this->containerBuilder);
+ $containFormHandlerCompilerPass = false;
- $this->formHandlerBundle->build($this->containerBuilderMock);
+ foreach ($this->containerBuilder->getCompilerPassConfig()->getPasses() as $passe) {
+ if ($passe instanceof FormHandlerCompilerPass) {
+ $containFormHandlerCompilerPass = true;
+ break;
+ }
+ }
+
+ $this->assertTrue($containFormHandlerCompilerPass);
}
}
diff --git a/tests/FormHandlerTest.php b/tests/FormHandlerTest.php
index da3bed6..0c35bf7 100644
--- a/tests/FormHandlerTest.php
+++ b/tests/FormHandlerTest.php
@@ -1,35 +1,33 @@
formFactoryMock = $this->prophesize(FormFactoryInterface::class);
$this->formConfigMock = $this->prophesize(FormConfigInterface::class);
@@ -58,14 +56,14 @@ public function testCreateForm()
$this->formHandler->createForm('my_fake_type', null, 'my_fake_data', ['my_fake_options']);
}
- /**
- * @expectedException \Symftony\FormHandler\Exception\NotSubmittedFormException
- * @expectedExceptionMessage Not submitted form.
- */
public function testHandleRequestThrowNotSubmittedFormException()
{
+ $this->expectException(NotSubmittedFormException::class);
+ $this->expectExceptionMessage('Not submitted form.');
+
$this->formMock
->handleRequest('my_fake_request')
+ ->willReturn($this->formMock->reveal())
->shouldBeCalled();
$this->formMock
@@ -95,6 +93,7 @@ public function testHandleRequestNotSubmitted()
{
$this->formMock
->handleRequest('my_fake_request')
+ ->willReturn($this->formMock->reveal())
->shouldBeCalled();
$this->formMock
@@ -120,14 +119,14 @@ public function testHandleRequestNotSubmitted()
$this->assertEquals('my_fake_handler_not_submitted_data', $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request'));
}
- /**
- * @expectedException \Symftony\FormHandler\Exception\InvalidFormException
- * @expectedExceptionMessage Invalid form.
- */
public function testHandleRequestThrowInvalidFormException()
{
+ $this->expectException(InvalidFormException::class);
+ $this->expectExceptionMessage('Invalid form');
+
$this->formMock
->handleRequest('my_fake_request')
+ ->willReturn($this->formMock->reveal())
->shouldBeCalled();
$this->formMock
@@ -162,6 +161,7 @@ public function testHandleRequestInvalid()
{
$this->formMock
->handleRequest('my_fake_request')
+ ->willReturn($this->formMock->reveal())
->shouldBeCalled();
$this->formMock
@@ -192,14 +192,14 @@ public function testHandleRequestInvalid()
$this->assertEquals('my_fake_handler_invalid_data', $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request'));
}
- /**
- * @expectedException \Symftony\FormHandler\Exception\TransformationFailedFormException
- * @expectedExceptionMessage Transformation form failed.
- */
public function testHandleRequestThrowTransformationFailedFormException()
{
+ $this->expectException(TransformationFailedFormException::class);
+ $this->expectExceptionMessage('Transformation form failed.');
+
$this->formMock
->handleRequest('my_fake_request')
+ ->willReturn($this->formMock->reveal())
->shouldBeCalled();
$this->formMock
@@ -219,7 +219,7 @@ public function testHandleRequestThrowTransformationFailedFormException()
$this->formMock
->getTransformationFailure()
- ->willReturn(true)
+ ->willReturn(new TransformationFailedException())
->shouldBeCalled();
$this->formConfigMock
@@ -239,6 +239,7 @@ public function testHandleRequestTransformationFailed()
{
$this->formMock
->handleRequest('my_fake_request')
+ ->willReturn($this->formMock->reveal())
->shouldBeCalled()
->shouldBeCalled();
@@ -259,7 +260,7 @@ public function testHandleRequestTransformationFailed()
$this->formMock
->getTransformationFailure()
- ->willReturn(true)
+ ->willReturn(new TransformationFailedException())
->shouldBeCalled();
$this->formConfigMock
@@ -279,6 +280,7 @@ public function testHandleRequest()
{
$this->formMock
->handleRequest('my_fake_request')
+ ->willReturn($this->formMock->reveal())
->shouldBeCalled();
$this->formMock
@@ -298,7 +300,7 @@ public function testHandleRequest()
$this->formMock
->getTransformationFailure()
- ->willReturn(false)
+ ->willReturn(null)
->shouldBeCalled();
$this->formMock
@@ -309,12 +311,11 @@ public function testHandleRequest()
$this->assertEquals('my_fake_form_data', $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request'));
}
- /**
- * @expectedException \Symftony\FormHandler\Exception\NotSubmittedFormException
- * @expectedExceptionMessage Not submitted form.
- */
public function testHandleDataThrowNotSubmittedFormException()
{
+ $this->expectException(NotSubmittedFormException::class);
+ $this->expectExceptionMessage('Not submitted form.');
+
$this->formMock->getConfig()
->willReturn($this->formConfigMock)
->shouldBeCalled();
@@ -363,12 +364,11 @@ public function testHandleDataNotSubmitted()
$this->assertEquals('my_fake_handler_not_submitted_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_request']));
}
- /**
- * @expectedException \Symftony\FormHandler\Exception\InvalidFormException
- * @expectedExceptionMessage Invalid form.
- */
public function testHandleDataThrowInvalidFormException()
{
+ $this->expectException(InvalidFormException::class);
+ $this->expectExceptionMessage('Invalid form.');
+
$this->formMock->getConfig()
->willReturn($this->formConfigMock)
->shouldBeCalled();
@@ -385,7 +385,12 @@ public function testHandleDataThrowInvalidFormException()
->willReturn(false)
->shouldBeCalled();
- $this->formMock->submit(['my_fake_key' => 'my_fake_request_value'], 'my_fake_clear_missing')
+ $this->formMock->submit(['my_fake_key' => 'my_fake_request_value'], true)
+ ->willReturn($this->formMock->reveal())
+ ->shouldBeCalled();
+
+ $this->formMock->isSubmitted()
+ ->willReturn(true)
->shouldBeCalled();
$this->formMock->isValid()
@@ -400,7 +405,7 @@ public function testHandleDataThrowInvalidFormException()
->willReturn(true)
->shouldBeCalled();
- $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], 'my_fake_clear_missing');
+ $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true);
}
public function testHandleDataInvalid()
@@ -421,7 +426,12 @@ public function testHandleDataInvalid()
->willReturn(false)
->shouldBeCalled();
- $this->formMock->submit(['my_fake_key' => 'my_fake_request_value'], 'my_fake_clear_missing')
+ $this->formMock->submit(['my_fake_key' => 'my_fake_request_value'], true)
+ ->willReturn($this->formMock->reveal())
+ ->shouldBeCalled();
+
+ $this->formMock->isSubmitted()
+ ->willReturn(true)
->shouldBeCalled();
$this->formMock->isValid()
@@ -436,15 +446,14 @@ public function testHandleDataInvalid()
->willReturn('my_fake_handler_invalid_data')
->shouldBeCalled();
- $this->assertEquals('my_fake_handler_invalid_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], 'my_fake_clear_missing'));
+ $this->assertEquals('my_fake_handler_invalid_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true));
}
- /**
- * @expectedException \Symftony\FormHandler\Exception\TransformationFailedFormException
- * @expectedExceptionMessage Transformation form failed.
- */
public function testHandleDataThrowTransformationFailedFormException()
{
+ $this->expectException(TransformationFailedFormException::class);
+ $this->expectExceptionMessage('Transformation form failed.');
+
$this->formMock->getConfig()
->willReturn($this->formConfigMock)
->shouldBeCalled();
@@ -461,7 +470,12 @@ public function testHandleDataThrowTransformationFailedFormException()
->willReturn(false)
->shouldBeCalled();
- $this->formMock->submit(['my_fake_key' => 'my_fake_request_value'], 'my_fake_clear_missing')
+ $this->formMock->submit(['my_fake_key' => 'my_fake_request_value'], true)
+ ->willReturn($this->formMock->reveal())
+ ->shouldBeCalled();
+
+ $this->formMock->isSubmitted()
+ ->willReturn(true)
->shouldBeCalled();
$this->formMock->isValid()
@@ -469,7 +483,7 @@ public function testHandleDataThrowTransformationFailedFormException()
->shouldBeCalled();
$this->formMock->getTransformationFailure()
- ->willReturn(true)
+ ->willReturn(new TransformationFailedException())
->shouldBeCalled();
$this->formConfigMock->hasOption('handler_transformation_failed')
@@ -480,7 +494,7 @@ public function testHandleDataThrowTransformationFailedFormException()
->willReturn(true)
->shouldBeCalled();
- $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], 'my_fake_clear_missing');
+ $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true);
}
public function testHandleDataTransformationFailed()
@@ -501,7 +515,12 @@ public function testHandleDataTransformationFailed()
->willReturn(false)
->shouldBeCalled();
- $this->formMock->submit(['my_fake_key' => 'my_fake_request_value'], 'my_fake_clear_missing')
+ $this->formMock->submit(['my_fake_key' => 'my_fake_request_value'], true)
+ ->willReturn($this->formMock->reveal())
+ ->shouldBeCalled();
+
+ $this->formMock->isSubmitted()
+ ->willReturn(true)
->shouldBeCalled();
$this->formMock->isValid()
@@ -509,7 +528,7 @@ public function testHandleDataTransformationFailed()
->shouldBeCalled();
$this->formMock->getTransformationFailure()
- ->willReturn(true)
+ ->willReturn(new TransformationFailedException())
->shouldBeCalled();
$this->formConfigMock->hasOption('handler_transformation_failed')
@@ -520,7 +539,7 @@ public function testHandleDataTransformationFailed()
->willReturn('my_fake_handler_transformation_failed_data')
->shouldBeCalled();
- $this->assertEquals('my_fake_handler_transformation_failed_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], 'my_fake_clear_missing'));
+ $this->assertEquals('my_fake_handler_transformation_failed_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true));
}
public function testHandleData()
@@ -541,7 +560,12 @@ public function testHandleData()
->willReturn(false)
->shouldBeCalled();
- $this->formMock->submit(['my_fake_key' => 'my_fake_request_value'], 'my_fake_clear_missing')
+ $this->formMock->submit(['my_fake_key' => 'my_fake_request_value'], true)
+ ->willReturn($this->formMock->reveal())
+ ->shouldBeCalled();
+
+ $this->formMock->isSubmitted()
+ ->willReturn(true)
->shouldBeCalled();
$this->formMock->isValid()
@@ -549,13 +573,13 @@ public function testHandleData()
->shouldBeCalled();
$this->formMock->getTransformationFailure()
- ->willReturn(false)
+ ->willReturn(null)
->shouldBeCalled();
$this->formMock->getData()
->willReturn('my_fake_form_data')
->shouldBeCalled();
- $this->assertEquals('my_fake_form_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], 'my_fake_clear_missing'));
+ $this->assertEquals('my_fake_form_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true));
}
}