You are here

public function AbstractValidatorTest::testValidateSingleGroup in Plug 7

File

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

Class

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

Namespace

Symfony\Component\Validator\Tests\Validator

Code

public function testValidateSingleGroup() {
  $entity = new Entity();
  $callback = function ($value, ExecutionContextInterface $context) {
    $context
      ->addViolation('Message');
  };
  $this->metadata
    ->addConstraint(new Callback(array(
    'callback' => $callback,
    'groups' => 'Group 1',
  )));
  $this->metadata
    ->addConstraint(new Callback(array(
    'callback' => $callback,
    'groups' => 'Group 2',
  )));
  $violations = $this
    ->validate($entity, null, 'Group 2');

  /** @var ConstraintViolationInterface[] $violations */
  $this
    ->assertCount(1, $violations);
}