Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] Validate all groups when special group name * is specified in validate() method #50679

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

Open
wants to merge 5 commits into
base: 7.4
Choose a base branch
Loading
from
Open
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
Next Next commit
Validate all groups when special group name "*" is specified in
validate()
  • Loading branch information
dwgebler committed Jun 15, 2023
commit 72666bb8298ac990094777227d585f2b071a29ad
7 changes: 7 additions & 0 deletions 7 src/Symfony/Component/Validator/Mapping/GenericMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ public function hasConstraints(): bool
*/
public function findConstraints(string $group): array
{
if ('*' === $group) {
$constraints = [];
foreach ($this->constraintsByGroup as $groupConstraints) {
$constraints = array_merge($constraints, $groupConstraints);
}
return $constraints;
}
return $this->constraintsByGroup[$group] ?? [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,29 @@ public function testValidateMultipleGroups()
$this->assertCount(2, $violations);
}

public function testValidateAllGroups()
{
$entity = new Entity();

$callback = function ($value, ExecutionContextInterface $context) {
$context->addViolation('Message');
};

$this->metadata->addConstraint(new Callback([
'callback' => $callback,
'groups' => 'Group 1',
]));
$this->metadata->addConstraint(new Callback([
'callback' => $callback,
'groups' => 'Group 2',
]));

$violations = $this->validate($entity, null, '*');

/* @var ConstraintViolationInterface[] $violations */
$this->assertCount(2, $violations);
}

public function testReplaceDefaultGroupByGroupSequenceObject()
{
$entity = new Entity();
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.