Skip to content

Navigation Menu

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.3
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions 5 src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.4
---

* Add the special group name `*` which can be passed to `ValidatorInterface::validate()` to validate all constraints, regardless of their group.

6.3
---

Expand Down
9 changes: 9 additions & 0 deletions 9 src/Symfony/Component/Validator/Mapping/GenericMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ 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,32 @@ 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',
]));
$this->metadata->addConstraint(new Callback([
'callback' => $callback,
]));

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

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

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