You are here

public function LegacyExecutionContextTest::testGetPropertyPathWithNestedCollectionsAndAllMixed in Zircon Profile 8

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

File

vendor/symfony/validator/Tests/LegacyExecutionContextTest.php, line 284

Class

LegacyExecutionContextTest
@group legacy

Namespace

Symfony\Component\Validator\Tests

Code

public function testGetPropertyPathWithNestedCollectionsAndAllMixed() {
  $constraints = new Collection(array(
    'shelves' => new All(array(
      'constraints' => array(
        new Collection(array(
          'name' => new ConstraintA(),
          'books' => new All(array(
            'constraints' => array(
              new ConstraintA(),
            ),
          )),
        )),
      ),
    )),
    'name' => new ConstraintA(),
  ));
  $data = array(
    'shelves' => array(
      array(
        'name' => 'Research',
        'books' => array(
          'foo',
          'bar',
        ),
      ),
      array(
        'name' => 'VALID',
        'books' => array(
          'foozy',
          'VALID',
          'bazzy',
        ),
      ),
    ),
    'name' => 'Library',
  );
  $expectedViolationPaths = array(
    '[shelves][0][name]',
    '[shelves][0][books][0]',
    '[shelves][0][books][1]',
    '[shelves][1][books][0]',
    '[shelves][1][books][2]',
    '[name]',
  );
  $visitor = new ValidationVisitor('Root', $this->metadataFactory, new ConstraintValidatorFactory(), $this->translator);
  $context = new ExecutionContext($visitor, $this->translator, self::TRANS_DOMAIN);
  $context
    ->validateValue($data, $constraints);
  foreach ($context
    ->getViolations() as $violation) {
    $violationPaths[] = $violation
      ->getPropertyPath();
  }
  $this
    ->assertEquals($expectedViolationPaths, $violationPaths);
}