You are here

public function AbstractValidatorTest::testReplaceDefaultGroupWithArrayFromGroupSequenceProvider 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::testReplaceDefaultGroupWithArrayFromGroupSequenceProvider()

File

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

Class

AbstractValidatorTest
@since 2.5

Namespace

Symfony\Component\Validator\Tests\Validator

Code

public function testReplaceDefaultGroupWithArrayFromGroupSequenceProvider() {
  $sequence = 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());
}