You are here

public function AbstractValidatorTest::testValidateSingleGroup in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Tests/Validator/AbstractValidatorTest.php \Symfony\Component\Validator\Tests\Validator\AbstractValidatorTest::testValidateSingleGroup()

File

vendor/symfony/validator/Tests/Validator/AbstractValidatorTest.php, line 1038

Class

AbstractValidatorTest
@since 2.5

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);
}