Skip to content

Commit 9f5ce66

Browse files
bug symfony#57678 [Validator] Add setGroupProvider to AttributeLoader (Maximilian Zumbansen)
This PR was merged into the 7.0 branch. Discussion ---------- [Validator] Add `setGroupProvider` to `AttributeLoader` | Q | A | ------------- | --- | Branch? | 7.0 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix symfony#57677 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT Was introduced in `AnnotationLoader` and got removed during the 6.4->7.0 switch to the `AttributeLoader`. Fixes issue [symfony#57677](symfony#57677). <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the latest branch. - For new features, provide some code snippets to help understand usage. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Commits ------- a965d68 [Validator] add setGroupProvider to AttributeLoader
2 parents f8657e2 + a965d68 commit 9f5ce66

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Symfony/Component/Validator/Mapping/Loader/AttributeLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
3737
if ($constraint instanceof GroupSequence) {
3838
$metadata->setGroupSequence($constraint->groups);
3939
} elseif ($constraint instanceof GroupSequenceProvider) {
40+
$metadata->setGroupProvider($constraint->provider);
4041
$metadata->setGroupSequenceProvider(true);
4142
} elseif ($constraint instanceof Constraint) {
4243
$metadata->addConstraint($constraint);

src/Symfony/Component/Validator/Tests/Mapping/Loader/AttributeLoaderTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,22 @@ public function testLoadGroupSequenceProviderAttribute()
210210
$this->assertEquals($expected, $metadata);
211211
}
212212

213+
public function testLoadExternalGroupSequenceProvider()
214+
{
215+
$loader = $this->createAttributeLoader();
216+
$namespace = $this->getFixtureAttributeNamespace();
217+
218+
$metadata = new ClassMetadata($namespace.'\GroupProviderDto');
219+
$loader->loadClassMetadata($metadata);
220+
221+
$expected = new ClassMetadata($namespace.'\GroupProviderDto');
222+
$expected->setGroupProvider('Symfony\Component\Validator\Tests\Dummy\DummyGroupProvider');
223+
$expected->setGroupSequenceProvider(true);
224+
$expected->getReflectionClass();
225+
226+
$this->assertEquals($expected, $metadata);
227+
}
228+
213229
protected function createAttributeLoader(): AttributeLoader
214230
{
215231
return new AttributeLoader();
@@ -219,4 +235,9 @@ protected function getFixtureNamespace(): string
219235
{
220236
return 'Symfony\Component\Validator\Tests\Fixtures\NestedAttribute';
221237
}
238+
239+
protected function getFixtureAttributeNamespace(): string
240+
{
241+
return 'Symfony\Component\Validator\Tests\Fixtures\Attribute';
242+
}
222243
}

0 commit comments

Comments
 (0)