merged branch entering/form-validationlistener-remove-count (PR #8430)
This PR was squashed before being merged into the master branch (closes #8430).
Discussion
----------
[Form] Validation listener remove count()
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Removing what looks a extra count not needed.
Commits
-------
23a71e5
[Form] Validation listener remove count()
This commit is contained in:
commit
0a894bc800
|
@ -54,14 +54,12 @@ class ValidationListener implements EventSubscriberInterface
|
|||
// Validate the form in group "Default"
|
||||
$violations = $this->validator->validate($form);
|
||||
|
||||
if (count($violations) > 0) {
|
||||
foreach ($violations as $violation) {
|
||||
// Allow the "invalid" constraint to be put onto
|
||||
// non-synchronized forms
|
||||
$allowNonSynchronized = Form::ERR_INVALID === $violation->getCode();
|
||||
foreach ($violations as $violation) {
|
||||
// Allow the "invalid" constraint to be put onto
|
||||
// non-synchronized forms
|
||||
$allowNonSynchronized = Form::ERR_INVALID === $violation->getCode();
|
||||
|
||||
$this->violationMapper->mapViolation($violation, $form, $allowNonSynchronized);
|
||||
}
|
||||
$this->violationMapper->mapViolation($violation, $form, $allowNonSynchronized);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ use Symfony\Component\Form\Extension\Validator\Constraints\Form;
|
|||
use Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener;
|
||||
use Symfony\Component\PropertyAccess\PropertyPath;
|
||||
use Symfony\Component\Validator\ConstraintViolation;
|
||||
use Symfony\Component\Validator\ConstraintViolationList;
|
||||
|
||||
class ValidationListenerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -142,4 +143,23 @@ class ValidationListenerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$this->listener->validateForm(new FormEvent($form, null));
|
||||
}
|
||||
|
||||
public function testValidateWithEmptyViolationList()
|
||||
{
|
||||
$form = $this->getMockForm();
|
||||
$form->expects($this->once())
|
||||
->method('isRoot')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->validator
|
||||
->expects($this->once())
|
||||
->method('validate')
|
||||
->will($this->returnValue(new ConstraintViolationList()));
|
||||
|
||||
$this->violationMapper
|
||||
->expects($this->never())
|
||||
->method('mapViolation');
|
||||
|
||||
$this->listener->validateForm(new FormEvent($form, null));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
|
||||
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Validator\ConstraintViolationList;
|
||||
|
||||
class FormTypeValidatorExtensionTest extends TypeTestCase
|
||||
{
|
||||
|
@ -69,15 +70,20 @@ class FormTypeValidatorExtensionTest extends TypeTestCase
|
|||
|
||||
public function testSubmitValidatesData()
|
||||
{
|
||||
$builder = $this->factory->createBuilder('form', null, array(
|
||||
'validation_groups' => 'group',
|
||||
));
|
||||
$builder = $this->factory->createBuilder(
|
||||
'form',
|
||||
null,
|
||||
array(
|
||||
'validation_groups' => 'group',
|
||||
)
|
||||
);
|
||||
$builder->add('firstName', 'form');
|
||||
$form = $builder->getForm();
|
||||
|
||||
$this->validator->expects($this->once())
|
||||
->method('validate')
|
||||
->with($this->equalTo($form));
|
||||
->with($this->equalTo($form))
|
||||
->will($this->returnValue(new ConstraintViolationList()));
|
||||
|
||||
// specific data is irrelevant
|
||||
$form->submit(array());
|
||||
|
|
Reference in New Issue