You are here

public function AbstractValidatorTest::testValidateCustomGroupWhenDefaultGroupWasReplaced in Plug 7

File

lib/Symfony/validator/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php, line 1187

Class

AbstractValidatorTest
@since 2.5 @author Bernhard Schussek <bschussek@gmail.com>

Namespace

Symfony\Component\Validator\Tests\Validator

Code

public function testValidateCustomGroupWhenDefaultGroupWasReplaced() {
  $entity = new Entity();
  $callback1 = function ($value, ExecutionContextInterface $context) {
    $context
      ->addViolation('Violation in other group');
  };
  $callback2 = function ($value, ExecutionContextInterface $context) {
    $context
      ->addViolation('Violation in group sequence');
  };
  $this->metadata
    ->addConstraint(new Callback(array(
    'callback' => $callback1,
    'groups' => 'Other Group',
  )));
  $this->metadata
    ->addConstraint(new Callback(array(
    'callback' => $callback2,
    'groups' => 'Group 1',
  )));
  $sequence = new GroupSequence(array(
    'Group 1',
    'Entity',
  ));
  $this->metadata
    ->setGroupSequence($sequence);
  $violations = $this
    ->validate($entity, null, 'Other Group');

  /** @var ConstraintViolationInterface[] $violations */
  $this
    ->assertCount(1, $violations);
  $this
    ->assertSame('Violation in other group', $violations[0]
    ->getMessage());
}