diff --git a/src/Symfony/Component/Validator/Constraints/Collection.php b/src/Symfony/Component/Validator/Constraints/Collection.php index ac35a27d052c7..5d740a0af6384 100644 --- a/src/Symfony/Component/Validator/Constraints/Collection.php +++ b/src/Symfony/Component/Validator/Constraints/Collection.php @@ -103,6 +103,10 @@ private static function isFieldsOption($options): bool return true; } + if (null === $optionOrField) { + return true; + } + if (!\is_array($optionOrField)) { return false; } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php index 4ff8b6d6aac6a..63b56cb07b250 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php @@ -175,10 +175,14 @@ public function testEmptyFieldsInOptions() $this->assertSame('foo bar baz', $constraint->extraFieldsMessage); } - public function testEmptyConstraintListFor() + /** + * @testWith [[]] + * [null] + */ + public function testEmptyConstraintListForField(?array $fieldConstraint) { $constraint = new Collection([ - 'foo' => [], + 'foo' => $fieldConstraint, ], null, null, @@ -193,11 +197,15 @@ public function testEmptyConstraintListFor() $this->assertSame('foo bar baz', $constraint->extraFieldsMessage); } - public function testEmptyConstraintListForFieldInOptions() + /** + * @testWith [[]] + * [null] + */ + public function testEmptyConstraintListForFieldInOptions(?array $fieldConstraint) { $constraint = new Collection([ 'fields' => [ - 'foo' => [], + 'foo' => $fieldConstraint, ], 'allowExtraFields' => true, 'extraFieldsMessage' => 'foo bar baz',