10000 [Validator] Fix fields without constraints in `Collection` · symfony/symfony@f6217d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit f6217d8

Browse files
committed
[Validator] Fix fields without constraints in Collection
1 parent b341535 commit f6217d8

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/Symfony/Component/Validator/Constraints/Collection.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,20 @@ private static function isFieldsOption($options): bool
9494
return false;
9595
}
9696

97-
if ([] === $options) {
98-
return true;
99-
}
100-
10197
foreach ($options as $optionOrField) {
10298
if ($optionOrField instanceof Constraint) {
10399
return true;
104100
}
105101

102+
if (null === $optionOrField) {
103+
continue;
104+
}
105+
106106
if (!\is_array($optionOrField)) {
107107
return false;
108108
}
109109

110-
if ([] !== $optionOrField && !($optionOrField[0] ?? null) instanceof Constraint) {
110+
if ($optionOrField && !($optionOrField[0] ?? null) instanceof Constraint) {
111111
return false;
112112
}
113113
}

src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,15 @@ public function testEmptyFieldsInOptions()
175175
$this->assertSame('foo bar baz', $constraint->extraFieldsMessage);
176176
}
177177

178-
public function testEmptyConstraintListFor()
178+
/**
179+
* @testWith [[]]
180+
* [null]
181+
*/
182+
public function testEmptyConstraintListForField(?array $fieldConstraint)
179183
{
180-
$constraint = new Collection([
181-
'foo' => [],
184+
$constraint = new Collection(
185+
[
186+
'foo' => $fieldConstraint,
182187
],
183188
null,
184189
null,
@@ -193,11 +198,15 @@ public function testEmptyConstraintListFor()
193198
$this->assertSame('foo bar baz', $constraint->extraFieldsMessage);
194199
}
195200

196-
public function testEmptyConstraintListForFieldInOptions()
201+
/**
202+
* @testWith [[]]
203+
* [null]
204+
*/
205+
public function testEmptyConstraintListForFieldInOptions(?array $fieldConstraint)
197206
{
198207
$constraint = new Collection([
199208
'fields' => [
200-
'foo' => [],
209+
'foo' => $fieldConstraint,
201210
],
202211
'allowExtraFields' => true,
203212
'extraFieldsMessage' => 'foo bar baz',

0 commit comments

Comments
 (0)
0