From 6df7a7223e95553c777d140c309d21d9e3490b8a Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Fri, 13 Apr 2012 16:42:01 +0200 Subject: [PATCH] [Form] Deprecated FormValidatorInterface and moved implementations to event listeners --- CHANGELOG-2.1.md | 2 + UPGRADE-2.1.md | 9 + .../Component/Form/CallbackValidator.php | 15 +- .../ValidationListener.php} | 24 ++- .../Form/Extension/Core/Type/FieldType.php | 4 +- .../DelegatingValidationListener.php} | 161 ++++++++++-------- .../Type/FieldTypeValidatorExtension.php | 8 +- src/Symfony/Component/Form/Form.php | 5 +- src/Symfony/Component/Form/FormBuilder.php | 7 + src/Symfony/Component/Form/FormEvents.php | 2 - .../Component/Form/FormValidatorInterface.php | 11 ++ .../Form/Resources/config/validation.xml | 4 +- .../DelegatingValidationListenerTest.php} | 88 +++++----- 13 files changed, 201 insertions(+), 139 deletions(-) rename src/Symfony/Component/Form/Extension/Core/{Validator/DefaultValidator.php => EventListener/ValidationListener.php} (71%) rename src/Symfony/Component/Form/Extension/Validator/{Validator/DelegatingValidator.php => EventListener/DelegatingValidationListener.php} (93%) rename src/Symfony/Component/Form/Tests/Extension/Validator/{Validator/DelegatingValidatorTest.php => EventListener/DelegatingValidationListenerTest.php} (90%) diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 449cc7701a..39e668c405 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -267,6 +267,8 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c in their name anymore. Their names terminate with "[]" now. * [BC BREAK] FormType::getDefaultOptions() and FormType::getAllowedOptionValues() don't receive an options array anymore. + * Deprecated FormValidatorInterface and substituted its implementations + by event subscribers ### HttpFoundation diff --git a/UPGRADE-2.1.md b/UPGRADE-2.1.md index f14ff75806..d410262a30 100644 --- a/UPGRADE-2.1.md +++ b/UPGRADE-2.1.md @@ -417,6 +417,14 @@ `FormEvents::PRE_BIND`, `FormEvents::BIND_CLIENT_DATA` or `FormEvents::BIND_NORM_DATA`. + * The interface FormValidatorInterface was deprecated and will be removed + in Symfony 2.3. + + If you implemented custom validators using this interface, you can + substitute them by event listeners listening to the FormEvents::POST_BIND + (or any other of the BIND events). In case you used the CallbackValidator + class, you should now pass the callback directly to `addEventListener`. + ### Session * Flash messages now return an array based on their type. The old method is @@ -543,6 +551,7 @@ To use mock session storage use the following. `handler_id` is irrelevant in th session: storage_id: session.storage.mock_file ``` + ### WebProfilerBundle * You must clear old profiles after upgrading to 2.1. If you are using a diff --git a/src/Symfony/Component/Form/CallbackValidator.php b/src/Symfony/Component/Form/CallbackValidator.php index b40de171fb..6d677c11f0 100644 --- a/src/Symfony/Component/Form/CallbackValidator.php +++ b/src/Symfony/Component/Form/CallbackValidator.php @@ -11,17 +11,28 @@ namespace Symfony\Component\Form; +/** + * Deprecated. You should use FormEvents::POST_BIND event listeners instead. + * + * @author Bernhard Schussek + * + * @deprecated Deprecated since version 2.1, to be removed in 2.3. + */ class CallbackValidator implements FormValidatorInterface { private $callback; + /** + * @deprecated Deprecated since version 2.1, to be removed in 2.3. + */ public function __construct($callback) { - // TODO validate callback - $this->callback = $callback; } + /** + * @deprecated Deprecated since version 2.1, to be removed in 2.3. + */ public function validate(FormInterface $form) { return call_user_func($this->callback, $form); diff --git a/src/Symfony/Component/Form/Extension/Core/Validator/DefaultValidator.php b/src/Symfony/Component/Form/Extension/Core/EventListener/ValidationListener.php similarity index 71% rename from src/Symfony/Component/Form/Extension/Core/Validator/DefaultValidator.php rename to src/Symfony/Component/Form/Extension/Core/EventListener/ValidationListener.php index 7268a3ee2f..a10959ced4 100644 --- a/src/Symfony/Component/Form/Extension/Core/Validator/DefaultValidator.php +++ b/src/Symfony/Component/Form/Extension/Core/EventListener/ValidationListener.php @@ -9,16 +9,30 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Form\Extension\Core\Validator; +namespace Symfony\Component\Form\Extension\Core\EventListener; -use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormValidatorInterface; use Symfony\Component\Form\FormError; +use Symfony\Component\Form\FormEvents; +use Symfony\Component\Form\Event\DataEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class DefaultValidator implements FormValidatorInterface +/** + * @author Bernhard Schussek + */ +class ValidationListener implements EventSubscriberInterface { - public function validate(FormInterface $form) + /** + * {@inheritdoc} + */ + static public function getSubscribedEvents() { + return array(FormEvents::POST_BIND => 'validateForm'); + } + + public function validateForm(DataEvent $event) + { + $form = $event->getForm(); + if (!$form->isSynchronized()) { $form->addError(new FormError( $form->getAttribute('invalid_message'), diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php b/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php index f68c878aad..b676d81984 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php @@ -19,7 +19,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormView; use Symfony\Component\Form\Extension\Core\EventListener\TrimListener; -use Symfony\Component\Form\Extension\Core\Validator\DefaultValidator; +use Symfony\Component\Form\Extension\Core\EventListener\ValidationListener; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Form\Exception\FormException; @@ -60,7 +60,7 @@ class FieldType extends AbstractType ->setAttribute('invalid_message_parameters', $options['invalid_message_parameters']) ->setAttribute('translation_domain', $options['translation_domain']) ->setData($options['data']) - ->addValidator(new DefaultValidator()) + ->addEventSubscriber(new ValidationListener()) ; if ($options['trim']) { diff --git a/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php b/src/Symfony/Component/Form/Extension/Validator/EventListener/DelegatingValidationListener.php similarity index 93% rename from src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php rename to src/Symfony/Component/Form/Extension/Validator/EventListener/DelegatingValidationListener.php index e3832fe143..116b804b24 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/EventListener/DelegatingValidationListener.php @@ -9,94 +9,33 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Form\Extension\Validator\Validator; +namespace Symfony\Component\Form\Extension\Validator\EventListener; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormValidatorInterface; use Symfony\Component\Form\FormError; -use Symfony\Component\Form\Util\VirtualFormAwareIterator; +use Symfony\Component\Form\FormEvents; +use Symfony\Component\Form\Event\DataEvent; use Symfony\Component\Form\Exception\FormException; +use Symfony\Component\Form\Util\VirtualFormAwareIterator; use Symfony\Component\Form\Util\PropertyPath; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ValidatorInterface; use Symfony\Component\Validator\ExecutionContext; -class DelegatingValidator implements FormValidatorInterface +/** + * @author Bernhard Schussek + */ +class DelegatingValidationListener implements EventSubscriberInterface { private $validator; - public function __construct(ValidatorInterface $validator) - { - $this->validator = $validator; - } - /** - * Validates the form and its domain object. - * - * @param FormInterface $form A FormInterface instance + * {@inheritdoc} */ - public function validate(FormInterface $form) + static public function getSubscribedEvents() { - if ($form->isRoot()) { - $mapping = array(); - $forms = array(); - - $this->buildFormPathMapping($form, $mapping); - $this->buildDataPathMapping($form, $mapping); - $this->buildNamePathMapping($form, $forms); - $this->resolveMappingPlaceholders($mapping, $forms); - - // Validate the form in group "Default" - // Validation of the data in the custom group is done by validateData(), - // which is constrained by the Execute constraint - if ($form->hasAttribute('validation_constraint')) { - $violations = $this->validator->validateValue( - $form->getData(), - $form->getAttribute('validation_constraint'), - self::getFormValidationGroups($form) - ); - - if ($violations) { - foreach ($violations as $violation) { - $propertyPath = new PropertyPath($violation->getPropertyPath()); - $template = $violation->getMessageTemplate(); - $parameters = $violation->getMessageParameters(); - $pluralization = $violation->getMessagePluralization(); - $error = new FormError($template, $parameters, $pluralization); - - $child = $form; - foreach ($propertyPath->getElements() as $element) { - $children = $child->getChildren(); - if (!isset($children[$element])) { - $form->addError($error); - break; - } - - $child = $children[$element]; - } - - $child->addError($error); - } - } - } elseif (count($violations = $this->validator->validate($form))) { - foreach ($violations as $violation) { - $propertyPath = $violation->getPropertyPath(); - $template = $violation->getMessageTemplate(); - $parameters = $violation->getMessageParameters(); - $pluralization = $violation->getMessagePluralization(); - $error = new FormError($template, $parameters, $pluralization); - - foreach ($mapping as $mappedPath => $child) { - if (preg_match($mappedPath, $propertyPath)) { - $child->addError($error); - continue 2; - } - } - - $form->addError($error); - } - } - } + return array(FormEvents::POST_BIND => 'validateForm'); } /** @@ -175,6 +114,82 @@ class DelegatingValidator implements FormValidatorInterface return (array) $groups; } + public function __construct(ValidatorInterface $validator) + { + $this->validator = $validator; + } + + /** + * Validates the form and its domain object. + * + * @param DataEvent $event The event object + */ + public function validateForm(DataEvent $event) + { + $form = $event->getForm(); + + if ($form->isRoot()) { + $mapping = array(); + $forms = array(); + + $this->buildFormPathMapping($form, $mapping); + $this->buildDataPathMapping($form, $mapping); + $this->buildNamePathMapping($form, $forms); + $this->resolveMappingPlaceholders($mapping, $forms); + + // Validate the form in group "Default" + // Validation of the data in the custom group is done by validateData(), + // which is constrained by the Execute constraint + if ($form->hasAttribute('validation_constraint')) { + $violations = $this->validator->validateValue( + $form->getData(), + $form->getAttribute('validation_constraint'), + self::getFormValidationGroups($form) + ); + + if ($violations) { + foreach ($violations as $violation) { + $propertyPath = new PropertyPath($violation->getPropertyPath()); + $template = $violation->getMessageTemplate(); + $parameters = $violation->getMessageParameters(); + $pluralization = $violation->getMessagePluralization(); + $error = new FormError($template, $parameters, $pluralization); + + $child = $form; + foreach ($propertyPath->getElements() as $element) { + $children = $child->getChildren(); + if (!isset($children[$element])) { + $form->addError($error); + break; + } + + $child = $children[$element]; + } + + $child->addError($error); + } + } + } elseif (count($violations = $this->validator->validate($form))) { + foreach ($violations as $violation) { + $propertyPath = $violation->getPropertyPath(); + $template = $violation->getMessageTemplate(); + $parameters = $violation->getMessageParameters(); + $pluralization = $violation->getMessagePluralization(); + $error = new FormError($template, $parameters, $pluralization); + + foreach ($mapping as $mappedPath => $child) { + if (preg_match($mappedPath, $propertyPath)) { + $child->addError($error); + continue 2; + } + } + + $form->addError($error); + } + } + } + } + private function buildFormPathMapping(FormInterface $form, array &$mapping, $formPath = 'children', $namePath = '') { foreach ($form->getAttribute('error_mapping') as $nestedDataPath => $nestedNamePath) { diff --git a/src/Symfony/Component/Form/Extension/Validator/Type/FieldTypeValidatorExtension.php b/src/Symfony/Component/Form/Extension/Validator/Type/FieldTypeValidatorExtension.php index fb8998323b..8d0db3f4f6 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Type/FieldTypeValidatorExtension.php +++ b/src/Symfony/Component/Form/Extension/Validator/Type/FieldTypeValidatorExtension.php @@ -13,9 +13,12 @@ namespace Symfony\Component\Form\Extension\Validator\Type; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\FormBuilder; -use Symfony\Component\Form\Extension\Validator\Validator\DelegatingValidator; +use Symfony\Component\Form\Extension\Validator\EventListener\DelegatingValidationListener; use Symfony\Component\Validator\ValidatorInterface; +/** + * @author Bernhard Schussek + */ class FieldTypeValidatorExtension extends AbstractTypeExtension { private $validator; @@ -39,7 +42,8 @@ class FieldTypeValidatorExtension extends AbstractTypeExtension ->setAttribute('validation_groups', $options['validation_groups']) ->setAttribute('validation_constraint', $options['validation_constraint']) ->setAttribute('cascade_validation', $options['cascade_validation']) - ->addValidator(new DelegatingValidator($this->validator)); + ->addEventSubscriber(new DelegatingValidationListener($this->validator)) + ; } public function getDefaultOptions() diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index b222c5ef3a..2c8f3c622c 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -573,9 +573,6 @@ class Form implements \IteratorAggregate, FormInterface $validator->validate($this); } - $event = new DataEvent($this, $clientData); - $this->dispatcher->dispatch(FormEvents::POST_VALIDATE, $event); - return $this; } @@ -808,6 +805,8 @@ class Form implements \IteratorAggregate, FormInterface * Returns the Validators * * @return array An array of FormValidatorInterface + * + * @deprecated Deprecated since version 2.1, to be removed in 2.3. */ public function getValidators() { diff --git a/src/Symfony/Component/Form/FormBuilder.php b/src/Symfony/Component/Form/FormBuilder.php index 42b94ec4f0..208a518518 100644 --- a/src/Symfony/Component/Form/FormBuilder.php +++ b/src/Symfony/Component/Form/FormBuilder.php @@ -17,6 +17,9 @@ use Symfony\Component\Form\Exception\CircularReferenceException; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +/** + * @author Bernhard Schussek + */ class FormBuilder { /** @@ -261,6 +264,8 @@ class FormBuilder * @param FormValidatorInterface $validator The validator * * @return FormBuilder The current builder + * + * @deprecated Deprecated since version 2.1, to be removed in 2.3. */ public function addValidator(FormValidatorInterface $validator) { @@ -273,6 +278,8 @@ class FormBuilder * Returns the validators used by the form. * * @return array An array of FormValidatorInterface + * + * @deprecated Deprecated since version 2.1, to be removed in 2.3. */ public function getValidators() { diff --git a/src/Symfony/Component/Form/FormEvents.php b/src/Symfony/Component/Form/FormEvents.php index a97337ec5a..08f10c4a43 100644 --- a/src/Symfony/Component/Form/FormEvents.php +++ b/src/Symfony/Component/Form/FormEvents.php @@ -29,6 +29,4 @@ final class FormEvents const BIND_NORM_DATA = 'form.bind_norm_data'; const SET_DATA = 'form.set_data'; - - const POST_VALIDATE = 'form.post_validate'; } diff --git a/src/Symfony/Component/Form/FormValidatorInterface.php b/src/Symfony/Component/Form/FormValidatorInterface.php index 913f33a0b4..6fa541b6ab 100644 --- a/src/Symfony/Component/Form/FormValidatorInterface.php +++ b/src/Symfony/Component/Form/FormValidatorInterface.php @@ -11,7 +11,18 @@ namespace Symfony\Component\Form; +/** + * This interface is deprecated. You should use a FormEvents::POST_BIND event + * listener instead. + * + * @author Bernhard Schussek + * + * @deprecated Deprecated since version 2.1, to be removed in 2.3. + */ interface FormValidatorInterface { + /** + * @deprecated Deprecated since version 2.1, to be removed in 2.3. + */ function validate(FormInterface $form); } diff --git a/src/Symfony/Component/Form/Resources/config/validation.xml b/src/Symfony/Component/Form/Resources/config/validation.xml index 7bd69402c0..494976c3ef 100644 --- a/src/Symfony/Component/Form/Resources/config/validation.xml +++ b/src/Symfony/Component/Form/Resources/config/validation.xml @@ -7,11 +7,11 @@ - Symfony\Component\Form\Extension\Validator\Validator\DelegatingValidator + Symfony\Component\Form\Extension\Validator\EventListener\DelegatingValidationListener validateFormData - Symfony\Component\Form\Extension\Validator\Validator\DelegatingValidator + Symfony\Component\Form\Extension\Validator\EventListener\DelegatingValidationListener validateFormChildren diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Validator/DelegatingValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/EventListener/DelegatingValidationListenerTest.php similarity index 90% rename from src/Symfony/Component/Form/Tests/Extension/Validator/Validator/DelegatingValidatorTest.php rename to src/Symfony/Component/Form/Tests/Extension/Validator/EventListener/DelegatingValidationListenerTest.php index a2b3387e89..8c6a5bb538 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Validator/DelegatingValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/EventListener/DelegatingValidationListenerTest.php @@ -9,20 +9,20 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Form\Tests\Extension\Validator\Validator; - -use Symfony\Component\Validator\GlobalExecutionContext; +namespace Symfony\Component\Form\Tests\Extension\Validator\EventListener; +use Symfony\Component\Form\Event\DataEvent; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormError; use Symfony\Component\Form\Util\PropertyPath; -use Symfony\Component\Form\Extension\Validator\Validator\DelegatingValidator; +use Symfony\Component\Form\Extension\Validator\EventListener\DelegatingValidationListener; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintViolation; +use Symfony\Component\Validator\GlobalExecutionContext; use Symfony\Component\Validator\ExecutionContext; -class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase +class DelegatingValidationListenerTest extends \PHPUnit_Framework_TestCase { private $dispatcher; @@ -40,18 +40,10 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase protected function setUp() { - if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { - $this->markTestSkipped('The "EventDispatcher" component is not available'); - } - - if (!class_exists('Symfony\Component\Validator\Constraint')) { - $this->markTestSkipped('The "Validator" component is not available'); - } - $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); $this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); $this->delegate = $this->getMock('Symfony\Component\Validator\ValidatorInterface'); - $this->validator = new DelegatingValidator($this->delegate); + $this->listener = new DelegatingValidationListener($this->delegate); $this->message = 'Message'; $this->params = array('foo' => 'bar'); } @@ -131,7 +123,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->delegate->expects($this->once())->method('validateValue'); - $this->validator->validate($form); + $this->listener->validateForm(new DataEvent($form, null)); } public function testFormErrorsOnForm() @@ -144,7 +136,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('constrainedProp') ))); - $this->validator->validate($form); + $this->listener->validateForm(new DataEvent($form, null)); $this->assertEquals(array($this->getFormError()), $form->getErrors()); } @@ -162,7 +154,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('children.data.firstName') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertEquals(array($this->getFormError()), $child->getErrors()); @@ -181,7 +173,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('children[address].data.street.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertEquals(array($this->getFormError()), $child->getErrors()); @@ -202,7 +194,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('children[address].data.street') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertFalse($child->hasErrors()); @@ -224,7 +216,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('children[address].constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertEquals(array($this->getFormError()), $child->getErrors()); @@ -244,7 +236,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('children[lastName].constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertEquals(array($this->getFormError()), $parent->getErrors()); $this->assertFalse($child->hasErrors()); @@ -267,7 +259,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('children[1].data.firstName'), ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); @@ -290,7 +282,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('data.constrainedProp') ))); - $this->validator->validate($form); + $this->listener->validateForm(new DataEvent($form, null)); $this->assertEquals(array($this->getFormError()), $form->getErrors()); } @@ -308,7 +300,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('data.firstName.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertEquals(array($this->getFormError()), $child->getErrors()); @@ -327,7 +319,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('data.address.street.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertEquals(array($this->getFormError()), $child->getErrors()); @@ -348,7 +340,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('data.address.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertEquals(array($this->getFormError()), $child->getErrors()); @@ -370,7 +362,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('data.address.street.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertFalse($child->hasErrors()); @@ -392,7 +384,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('children[address].data.street.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertFalse($child->hasErrors()); @@ -414,7 +406,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('data[address].street.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertFalse($child->hasErrors()); @@ -434,7 +426,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('data.lastName.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertEquals(array($this->getFormError()), $parent->getErrors()); $this->assertFalse($child->hasErrors()); @@ -463,7 +455,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $child->setData(array()); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors(), '->hasErrors() returns false for parent form'); $this->assertFalse($child->hasErrors(), '->hasErrors() returns false for child form'); @@ -494,7 +486,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('data.passwordPlain.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertEquals(array($this->getFormError()), $child->getErrors()); @@ -519,7 +511,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('data.address.streetName.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertFalse($child->hasErrors()); @@ -545,7 +537,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('children[address].data.streetName.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertFalse($child->hasErrors()); @@ -571,7 +563,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('data.address.streetName.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertFalse($child->hasErrors()); @@ -599,7 +591,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->getConstraintViolation('data.streetName.constrainedProp') ))); - $this->validator->validate($parent); + $this->listener->validateForm(new DataEvent($parent, null)); $this->assertFalse($parent->hasErrors()); $this->assertFalse($child->hasErrors()); @@ -624,7 +616,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $form->setData($object); - DelegatingValidator::validateFormData($form, $context); + DelegatingValidationListener::validateFormData($form, $context); } public function testValidateFormDataCanHandleCallbackValidationGroups() @@ -645,7 +637,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $form->setData($object); - DelegatingValidator::validateFormData($form, $context); + DelegatingValidationListener::validateFormData($form, $context); } public function testValidateFormDataCanHandleClosureValidationGroups() @@ -668,7 +660,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $form->setData($object); - DelegatingValidator::validateFormData($form, $context); + DelegatingValidationListener::validateFormData($form, $context); } public function testValidateFormDataUsesInheritedValidationGroup() @@ -691,7 +683,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase ->method('walkReference') ->with($object, 'group', 'foo.bar.data', true); - DelegatingValidator::validateFormData($child, $context); + DelegatingValidationListener::validateFormData($child, $context); } public function testValidateFormDataUsesInheritedCallbackValidationGroup() @@ -717,7 +709,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase ->method('walkReference') ->with($object, 'group2', 'foo.bar.data', true); - DelegatingValidator::validateFormData($child, $context); + DelegatingValidationListener::validateFormData($child, $context); } public function testValidateFormDataUsesInheritedClosureValidationGroup() @@ -745,7 +737,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase ->method('walkReference') ->with($object, 'group2', 'foo.bar.data', true); - DelegatingValidator::validateFormData($child, $context); + DelegatingValidationListener::validateFormData($child, $context); } public function testValidateFormDataAppendsPropertyPath() @@ -761,7 +753,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $form->setData($object); - DelegatingValidator::validateFormData($form, $context); + DelegatingValidationListener::validateFormData($form, $context); } public function testValidateFormDataDoesNotWalkScalars() @@ -783,7 +775,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $form->bind(array('foo' => 'bar')); // reverse transformed to "foobar" - DelegatingValidator::validateFormData($form, $context); + DelegatingValidationListener::validateFormData($form, $context); } public function testValidateFormChildren() @@ -802,7 +794,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase // constraint is in the Default group as well ->with($form->getChildren(), Constraint::DEFAULT_GROUP, 'children', true); - DelegatingValidator::validateFormChildren($form, $context); + DelegatingValidationListener::validateFormChildren($form, $context); } public function testValidateFormChildrenAppendsPropertyPath() @@ -818,7 +810,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase ->method('walkReference') ->with($form->getChildren(), 'Default', 'foo.bar.children', true); - DelegatingValidator::validateFormChildren($form, $context); + DelegatingValidationListener::validateFormChildren($form, $context); } public function testValidateFormChildrenDoesNothingIfDisabled() @@ -833,7 +825,7 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $graphWalker->expects($this->never()) ->method('walkReference'); - DelegatingValidator::validateFormChildren($form, $context); + DelegatingValidationListener::validateFormChildren($form, $context); } public function testValidateIgnoresNonRoot() @@ -846,6 +838,6 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase $this->delegate->expects($this->never()) ->method('validate'); - $this->validator->validate($form); + $this->listener->validateForm(new DataEvent($form, null)); } }