You are here

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

File

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

Class

AbstractValidatorTest
@since 2.5

Namespace

Symfony\Component\Validator\Tests\Validator

Code

public function testPropagateDefaultGroupToReferenceWhenReplacingDefaultGroup() {
  $entity = new Entity();
  $entity->reference = new Reference();
  $callback1 = function ($value, ExecutionContextInterface $context) {
    $context
      ->addViolation('Violation in Default group');
  };
  $callback2 = function ($value, ExecutionContextInterface $context) {
    $context
      ->addViolation('Violation in group sequence');
  };
  $this->metadata
    ->addPropertyConstraint('reference', new Valid());
  $this->referenceMetadata
    ->addConstraint(new Callback(array(
    'callback' => $callback1,
    'groups' => 'Default',
  )));
  $this->referenceMetadata
    ->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, 'Default');

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