Skip to content

Commit

Permalink
[Validator] Fix fields without constraints in Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
HypeMC committed Feb 4, 2024
1 parent 89b3d63 commit 9de3680
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Collection.php
Expand Up @@ -103,6 +103,10 @@ private static function isFieldsOption($options): bool
return true;
}

if (null === $optionOrField) {
return true;
}

if (!\is_array($optionOrField)) {
return false;
}
Expand Down
Expand Up @@ -175,10 +175,15 @@ public function testEmptyFieldsInOptions()
$this->assertSame('foo bar baz', $constraint->extraFieldsMessage);
}

public function testEmptyConstraintListFor()
/**
* @testWith [[]]
* [null]
*/
public function testEmptyConstraintListForField(?array $fieldConstraint)
{
$constraint = new Collection([
'foo' => [],
$constraint = new Collection(
[
'foo' => $fieldConstraint,
],
null,
null,
Expand All @@ -193,11 +198,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',
Expand Down

0 comments on commit 9de3680

Please sign in to comment.