You are here

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

File

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

Class

AbstractValidatorTest
@since 2.5

Namespace

Symfony\Component\Validator\Tests\Validator

Code

public function testRecursiveArrayReference() {
  $test = $this;
  $entity = new Entity();
  $entity->reference = array(
    2 => array(
      'key' => new Reference(),
    ),
  );
  $callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
    $test
      ->assertSame($test::REFERENCE_CLASS, $context
      ->getClassName());
    $test
      ->assertNull($context
      ->getPropertyName());
    $test
      ->assertSame('reference[2][key]', $context
      ->getPropertyPath());
    $test
      ->assertSame('Group', $context
      ->getGroup());
    $test
      ->assertSame($test->referenceMetadata, $context
      ->getMetadata());
    $test
      ->assertSame($entity, $context
      ->getRoot());
    $test
      ->assertSame($entity->reference[2]['key'], $context
      ->getValue());
    $test
      ->assertSame($entity->reference[2]['key'], $value);
    $context
      ->addViolation('Message %param%', array(
      '%param%' => 'value',
    ));
  };
  $this->metadata
    ->addPropertyConstraint('reference', new Valid());
  $this->referenceMetadata
    ->addConstraint(new Callback(array(
    'callback' => $callback,
    'groups' => 'Group',
  )));
  $violations = $this
    ->validate($entity, 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('reference[2][key]', $violations[0]
    ->getPropertyPath());
  $this
    ->assertSame($entity, $violations[0]
    ->getRoot());
  $this
    ->assertSame($entity->reference[2]['key'], $violations[0]
    ->getInvalidValue());
  $this
    ->assertNull($violations[0]
    ->getPlural());
  $this
    ->assertNull($violations[0]
    ->getCode());
}