public function AbstractValidatorTest::testReplaceDefaultGroupWithObjectFromGroupSequenceProvider in Plug 7
File
- lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Tests/ Validator/ AbstractValidatorTest.php, line 1217
Class
- AbstractValidatorTest
- @since 2.5 @author Bernhard Schussek <bschussek@gmail.com>
Namespace
Symfony\Component\Validator\Tests\ValidatorCode
public function testReplaceDefaultGroupWithObjectFromGroupSequenceProvider() {
$sequence = new GroupSequence(array(
'Group 1',
'Group 2',
'Group 3',
'Entity',
));
$entity = new GroupSequenceProviderEntity($sequence);
$callback1 = function ($value, ExecutionContextInterface $context) {
$context
->addViolation('Violation in Group 2');
};
$callback2 = function ($value, ExecutionContextInterface $context) {
$context
->addViolation('Violation in Group 3');
};
$metadata = new ClassMetadata(get_class($entity));
$metadata
->addConstraint(new Callback(array(
'callback' => function () {
},
'groups' => 'Group 1',
)));
$metadata
->addConstraint(new Callback(array(
'callback' => $callback1,
'groups' => 'Group 2',
)));
$metadata
->addConstraint(new Callback(array(
'callback' => $callback2,
'groups' => 'Group 3',
)));
$metadata
->setGroupSequenceProvider(true);
$this->metadataFactory
->addMetadata($metadata);
$violations = $this
->validate($entity, null, 'Default');
/** @var ConstraintViolationInterface[] $violations */
$this
->assertCount(1, $violations);
$this
->assertSame('Violation in Group 2', $violations[0]
->getMessage());
}