public function ValidationVisitorTest::testValidateCascadedPropertyValidatesTraversableByDefault

File

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

Class

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

Namespace

Symfony\Component\Validator\Tests

Code

public function testValidateCascadedPropertyValidatesTraversableByDefault() {
  $entity = new Entity();
  $entity->reference = new \ArrayIterator(array(
    'key' => new Entity(),
  ));

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

  // validate array 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),
    // generated by the reference
    new ConstraintViolation('Failed', 'Failed', array(), 'Root', 'reference[key]', $entity->reference['key']),
  ));
  $this
    ->assertEquals($violations, $this->visitor
    ->getViolations());
}