You are here

public function Abstract2Dot5ApiTest::testReferenceTraversalRecursionEnabledOnReferenceTraversalEnabledOnClass in Plug 7

File

lib/Symfony/validator/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php, line 509

Class

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

Namespace

Symfony\Component\Validator\Tests\Validator

Code

public function testReferenceTraversalRecursionEnabledOnReferenceTraversalEnabledOnClass() {
  $entity = new Entity();
  $entity->reference = new \ArrayIterator(array(
    2 => new \ArrayIterator(array(
      'key' => new Reference(),
    )),
  ));
  $callback = function ($value, ExecutionContextInterface $context) {
    $context
      ->addViolation('Message');
  };
  $traversableMetadata = new ClassMetadata('ArrayIterator');
  $traversableMetadata
    ->addConstraint(new Traverse(true));
  $this->metadataFactory
    ->addMetadata($traversableMetadata);
  $this->referenceMetadata
    ->addConstraint(new Callback(array(
    'callback' => $callback,
    'groups' => 'Group',
  )));
  $this->metadata
    ->addPropertyConstraint('reference', new Valid(array(
    'deep' => true,
  )));
  $violations = $this
    ->validate($entity, new Valid(), 'Group');

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