From 120778069bf081c6cb2926f42c178214bba816de Mon Sep 17 00:00:00 2001 From: Philipp Cordes Date: Sun, 6 Jan 2019 15:08:38 +0100 Subject: [PATCH] Implement failing test for issue #27090 --- .../Tests/Validator/AbstractValidatorTest.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php b/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php index 7d303ce8a5435..2342f195d6c0a 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php @@ -589,6 +589,31 @@ public function testRecursiveArrayReference() $this->assertNull($violations[0]->getCode()); } + // https://github.com/symfony/symfony/issues/27090 + public function testOnlyCascadedArraysAreTraversed() + { + $entity = new Entity(); + $entity->reference = array('key' => new Reference()); + + $callback = function ($value, ExecutionContextInterface $context) { + $context->addViolation('Message %param%', array('%param%' => 'value')); + }; + + $this->metadata->addPropertyConstraint('reference', new Callback(array( + 'callback' => function () {}, + 'groups' => 'Group', + ))); + $this->referenceMetadata->addConstraint(new Callback(array( + 'callback' => $callback, + 'groups' => 'Group', + ))); + + $violations = $this->validate($entity, null, 'Group'); + + /* @var ConstraintViolationInterface[] $violations */ + $this->assertCount(0, $violations); + } + public function testArrayTraversalCannotBeDisabled() { $entity = new Entity();