I have a Profile
entity with an email
field and I'm trying to validate it using Symfony Validator. I'm trying this using the GroupSequence feature because one of my constraints is fairly expensive from a computation point-of-view.
Basically, I want a valid email address and the domain should not be blacklisted (a custom constraint that uses an internal list of domains). The last constraint I want to be applied only if the email is valid, so I'm using the group sequence, but it's not working as expected.
I'm using Symfony 2.8.2 and I have the following validation.yml file:
Namespace\Entities\Profile:
group_sequence:
- Profile
- common
- email.strict
properties:
email:
- Email: { groups: [common, email.strict] }
- Namespace\ProfileBundle\Validators\Constraints\EmailNotBlacklisted: { groups: [email.strict] }
The validation is done like this:
$profile = new Profile();
$profile->setEmail('blacklisted.com');
$errors = $this->validator->validate($profile, array('common', 'email.strict'));
Given that blacklisted.com
is an invalid value, I'm expecting the Email
constraint to fail and therefore it should never reach the EmailNotBlacklisted
constraint.
However, $errors
contains errors from both constraints.
What am I doing wrong in this usage of group_sequence
feature?