You are here

public function Abstract2Dot5ApiTest::testGroupSequenceIncludesReferences in Zircon Profile 8

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

File

vendor/symfony/validator/Tests/Validator/Abstract2Dot5ApiTest.php, line 117

Class

Abstract2Dot5ApiTest
Verifies that a validator satisfies the API of Symfony 2.5+.

Namespace

Symfony\Component\Validator\Tests\Validator

Code

public function testGroupSequenceIncludesReferences() {
  $entity = new Entity();
  $entity->reference = new Reference();
  $callback1 = function ($value, ExecutionContextInterface $context) {
    $context
      ->addViolation('Reference violation 1');
  };
  $callback2 = function ($value, ExecutionContextInterface $context) {
    $context
      ->addViolation('Reference violation 2');
  };
  $this->metadata
    ->addPropertyConstraint('reference', new Valid());
  $this->referenceMetadata
    ->addConstraint(new Callback(array(
    'callback' => $callback1,
    'groups' => 'Group 1',
  )));
  $this->referenceMetadata
    ->addConstraint(new Callback(array(
    'callback' => $callback2,
    'groups' => 'Group 2',
  )));
  $sequence = new GroupSequence(array(
    'Group 1',
    'Entity',
  ));
  $violations = $this->validator
    ->validate($entity, new Valid(), $sequence);

  /* @var ConstraintViolationInterface[] $violations */
  $this
    ->assertCount(1, $violations);
  $this
    ->assertSame('Reference violation 1', $violations[0]
    ->getMessage());
}