8000 [Validator] Fix fields without constraints in `Collection` by HypeMC · Pull Request #53755 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Fix fields without constraints in Collection #53755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[Validator] Fix fields without constraints in Collection
  • Loading branch information
HypeMC committed Feb 7, 2024
commit f6217d87e66d950a8c61b9ea54af09282aa4734e
10 changes: 5 additions & 5 deletions src/Symfony/Component/Validator/Constraints/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ private static function isFieldsOption($options): bool
return false;
}

if ([] === $options) {
return true;
}

foreach ($options as $optionOrField) {
if ($optionOrField instanceof Constraint) {
return true;
}

if (null === $optionOrField) {
continue;
}

if (!\is_array($optionOrField)) {
return false;
}

if ([] !== $optionOrField && !($optionOrField[0] ?? null) instanceof Constraint) {
if ($optionOrField && !($optionOrField[0] ?? null) instanceof Constraint) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
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