Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Serializer] AdddefaultType
toDiscriminatorMap
#59828
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletionssrc/Symfony/Component/Serializer/Attribute/DiscriminatorMap.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletionssrc/Symfony/Component/Serializer/Mapping/ClassDiscriminatorMapping.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionssrc/Symfony/Component/Serializer/Mapping/Factory/ClassMetadataFactoryCompiler.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionsrc/Symfony/Component/Serializer/Mapping/Loader/AttributeLoader.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletionsrc/Symfony/Component/Serializer/Mapping/Loader/XmlFileLoader.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletionsrc/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions...ponent/Serializer/Mapping/Loader/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionsrc/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletionsrc/Symfony/Component/Serializer/Tests/Attribute/DiscriminatorMapTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -40,9 +40,16 @@ public function testExceptionWithEmptyTypeProperty() | ||
new DiscriminatorMap(typeProperty: '', mapping: ['foo' => 'FooClass']); | ||
} | ||
public functiontestExceptionWithEmptyMappingProperty() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
new DiscriminatorMap(typeProperty: 'type', mapping: []); | ||
} | ||
public function testExceptionWithMissingDefaultTypeInMapping() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
alanpoulain marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
$this->expectExceptionMessage(sprintf('Default type "bar" given to "%s" must be present in "mapping" types.', DiscriminatorMap::class)); | ||
new DiscriminatorMap(typeProperty: 'type', mapping: ['foo' => 'FooClass'], defaultType: 'bar'); | ||
} | ||
} |
2 changes: 1 addition & 1 deletionsrc/Symfony/Component/Serializer/Tests/Fixtures/Attributes/AbstractDummy.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletionsrc/Symfony/Component/Serializer/Tests/Mapping/Factory/ClassMetadataFactoryCompilerTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionsrc/Symfony/Component/Serializer/Tests/Mapping/Loader/AttributeLoaderTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionsrc/Symfony/Component/Serializer/Tests/Mapping/Loader/XmlFileLoaderTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionsrc/Symfony/Component/Serializer/Tests/Mapping/Loader/YamlFileLoaderTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletionssrc/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -560,6 +560,41 @@ public function hasMetadataFor($value): bool | ||
$this->assertInstanceOf(DummySecondChildQuux::class, $normalizedData->quux); | ||
} | ||
public function testDenormalizeWithDiscriminatorMapUsesCorrectClassnameWithDefaultType() | ||
{ | ||
$factory = new ClassMetadataFactory(new AttributeLoader()); | ||
$loaderMock = new class implements ClassMetadataFactoryInterface { | ||
public function getMetadataFor($value): ClassMetadataInterface | ||
{ | ||
if (AbstractDummy::class === $value) { | ||
return new ClassMetadata( | ||
AbstractDummy::class, | ||
new ClassDiscriminatorMapping('type', [ | ||
'first' => AbstractDummyFirstChild::class, | ||
'second' => AbstractDummySecondChild::class, | ||
], 'second') | ||
); | ||
} | ||
throw new InvalidArgumentException(sprintf('"%s" is not handled.', $value)); | ||
} | ||
public function hasMetadataFor($value): bool | ||
{ | ||
return AbstractDummy::class === $value; | ||
} | ||
}; | ||
$discriminatorResolver = new ClassDiscriminatorFromClassMetadata($loaderMock); | ||
$normalizer = new AbstractObjectNormalizerDummy($factory, null, new PhpDocExtractor(), $discriminatorResolver); | ||
$serializer = new Serializer([$normalizer]); | ||
$normalizer->setSerializer($serializer); | ||
alanpoulain marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
$normalizedData = $normalizer->denormalize(['foo' => 'foo', 'baz' => 'baz', 'quux' => ['value' => 'quux']], AbstractDummy::class); | ||
$this->assertInstanceOf(DummySecondChildQuux::class, $normalizedData->quux); | ||
} | ||
public function testDenormalizeWithDiscriminatorMapAndObjectToPopulateUsesCorrectClassname() | ||
{ | ||
$factory = new ClassMetadataFactory(new AttributeLoader()); | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.