public function ValidationVisitorTest::testValidateCascadedPropertyRecursesArraysByDefault

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/ValidationVisitorTest.php, line 442

Class

ValidationVisitorTest
@author Bernhard Schussek <bschussek@gmail.com>

Namespace

Symfony\Component\Validator\Tests

Code

public function testValidateCascadedPropertyRecursesArraysByDefault() {
  $entity = new Entity();
  $entity->reference = array(
    'key' => array(
      'nested' => new Entity(),
    ),
  );

  // add a constraint for the entity that always fails
  $this->metadata
    ->addConstraint(new FailingConstraint());

  // validate iterator when validating the property "reference"
  $this->metadata
    ->addPropertyConstraint('reference', new Valid());
  $this->visitor
    ->validate($entity, 'Default', '');
  $violations = new ConstraintViolationList(array(
    // generated by the root object
    new ConstraintViolation('Failed', 'Failed', array(), 'Root', '', $entity),
    // nothing generated by the reference!
    new ConstraintViolation('Failed', 'Failed', array(), 'Root', 'reference[key][nested]', $entity->reference['key']['nested']),
  ));
  $this
    ->assertEquals($violations, $this->visitor
    ->getViolations());
}