File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
tests/AutoMapperTest/DiscriminatorMapBadConfiguration Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ // This is not god! It should raise a proper exception, telling the key
2
+ // `linkType` is not present is the source
3
+ Error {
4
+ +class: "Error"
5
+ +message: "Cannot instantiate abstract class AutoMapper\Tests\AutoMapperTest\DiscriminatorMapBadConfiguration\LinkType"
6
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace AutoMapper \Tests \AutoMapperTest \DiscriminatorMapBadConfiguration ;
4
+
5
+ use AutoMapper \Tests \AutoMapperBuilder ;
6
+ use Symfony \Component \Serializer \Attribute \DiscriminatorMap ;
7
+
8
+ #[DiscriminatorMap('linkType ' , [
9
+ 'default ' => DefaultLinkType::class,
10
+ ])]
11
+ abstract class LinkType
12
+ {
13
+ }
14
+
15
+ class DefaultLinkType extends LinkType
16
+ {
17
+ public function __construct (
18
+ public string $ link ,
19
+ ) {
20
+ }
21
+ }
22
+
23
+ $ source = [
24
+ // There is a typo on the key `type`.
25
+ // It should be `linkType` instead of `type`.
26
+ 'type ' => 'default ' ,
27
+ 'link ' => 'https://example.com ' ,
28
+ ];
29
+
30
+ try {
31
+ return AutoMapperBuilder::buildAutoMapper ()->map ($ source , LinkType::class);
32
+ } catch (\Throwable $ th ) {
33
+ return $ th ;
34
+ }
You can’t perform that action at this time.
0 commit comments