You are here

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

File

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

Class

AbstractValidatorTest
@since 2.5

Namespace

Symfony\Component\Validator\Tests\Validator

Code

public function testRecursiveTraversable() {
  $test = $this;
  $entity = new Entity();
  $traversable = new \ArrayIterator(array(
    2 => new \ArrayIterator(array(
      'key' => $entity,
    )),
  ));
  $callback = function ($value, ExecutionContextInterface $context) use ($test, $entity, $traversable) {
    $test
      ->assertSame($test::ENTITY_CLASS, $context
      ->getClassName());
    $test
      ->assertNull($context
      ->getPropertyName());
    $test
      ->assertSame('[2][key]', $context
      ->getPropertyPath());
    $test
      ->assertSame('Group', $context
      ->getGroup());
    $test
      ->assertSame($test->metadata, $context
      ->getMetadata());
    $test
      ->assertSame($traversable, $context
      ->getRoot());
    $test
      ->assertSame($entity, $context
      ->getValue());
    $test
      ->assertSame($entity, $value);
    $context
      ->addViolation('Message %param%', array(
      '%param%' => 'value',
    ));
  };
  $this->metadata
    ->addConstraint(new Callback(array(
    'callback' => $callback,
    'groups' => 'Group',
  )));
  $violations = $this
    ->validate($traversable, null, 'Group');

  /* @var ConstraintViolationInterface[] $violations */
  $this
    ->assertCount(1, $violations);
  $this
    ->assertSame('Message value', $violations[0]
    ->getMessage());
  $this
    ->assertSame('Message %param%', $violations[0]
    ->getMessageTemplate());
  $this
    ->assertSame(array(
    '%param%' => 'value',
  ), $violations[0]
    ->getParameters());
  $this
    ->assertSame('[2][key]', $violations[0]
    ->getPropertyPath());
  $this
    ->assertSame($traversable, $violations[0]
    ->getRoot());
  $this
    ->assertSame($entity, $violations[0]
    ->getInvalidValue());
  $this
    ->assertNull($violations[0]
    ->getPlural());
  $this
    ->assertNull($violations[0]
    ->getCode());
}