1818use Patchlevel \Hydrator \Metadata \PropertyMetadataNotFound ;
1919use Patchlevel \Hydrator \Metadata \SubjectIdAndPersonalDataConflict ;
2020use Patchlevel \Hydrator \Normalizer \EnumNormalizer ;
21+ use Patchlevel \Hydrator \Normalizer \ObjectNormalizer ;
2122use Patchlevel \Hydrator \Tests \Unit \Fixture \BrokenParentDto ;
2223use Patchlevel \Hydrator \Tests \Unit \Fixture \DistributionCreated ;
2324use Patchlevel \Hydrator \Tests \Unit \Fixture \DuplicateFieldNameDto ;
2930use Patchlevel \Hydrator \Tests \Unit \Fixture \MissingSubjectIdDto ;
3031use Patchlevel \Hydrator \Tests \Unit \Fixture \ParentDto ;
3132use Patchlevel \Hydrator \Tests \Unit \Fixture \ParentWithPersonalDataDto ;
33+ use Patchlevel \Hydrator \Tests \Unit \Fixture \ProfileCreatedWithGeneric ;
3234use Patchlevel \Hydrator \Tests \Unit \Fixture \ProfileId ;
3335use Patchlevel \Hydrator \Tests \Unit \Fixture \Status ;
36+ use Patchlevel \Hydrator \Tests \Unit \Fixture \Wrapper ;
3437use PHPUnit \Framework \TestCase ;
3538
3639final class AttributeMetadataFactoryTest extends TestCase
@@ -136,7 +139,7 @@ public function __construct(
136139 self ::assertNull ($ propertyMetadata ->normalizer ());
137140 }
138141
139- public function testEventWithFieldName (): void
142+ public function testNormalizedName (): void
140143 {
141144 $ object = new class ('Foo ' ) {
142145 public function __construct (
@@ -160,7 +163,7 @@ public function __construct(
160163 self ::assertNull ($ propertyMetadata ->normalizer ());
161164 }
162165
163- public function testEventWithNormalizer (): void
166+ public function testDefineNormalizer (): void
164167 {
165168 $ object = new class (Email::fromString ('info@patchlevel.de ' )) {
166169 public function __construct (
@@ -184,7 +187,7 @@ public function __construct(
184187 self ::assertInstanceOf (EmailNormalizer::class, $ propertyMetadata ->normalizer ());
185188 }
186189
187- public function testEventWithTypeAwareNormalizer (): void
190+ public function testTypeAwareNormalizer (): void
188191 {
189192 $ object = new class (Status::Draft) {
190193 public function __construct (
@@ -212,7 +215,7 @@ public function __construct(
212215 self ::assertSame (Status::class, $ normalizer ->getEnum ());
213216 }
214217
215- public function testEventWithInferNormalizer (): void
218+ public function testInferNormalizer (): void
216219 {
217220 $ object = new class {
218221 public function __construct (
@@ -233,6 +236,34 @@ public function __construct(
233236 self ::assertEquals (new IdNormalizer (ProfileId::class), $ propertyMetadata ->normalizer ());
234237 }
235238
239+ public function testInferNormalizerWithGeneric (): void
240+ {
241+ $ metadataFactory = new AttributeMetadataFactory ();
242+ $ metadata = $ metadataFactory ->metadata (ProfileCreatedWithGeneric::class);
243+
244+ self ::assertCount (2 , $ metadata ->properties ());
245+
246+ $ propertyMetadata = $ metadata ->propertyForField ('email ' );
247+ self ::assertEquals (new ObjectNormalizer (Wrapper::class), $ propertyMetadata ->normalizer ());
248+ }
249+
250+ public function testInferNormalizerWithTemplate (): void
251+ {
252+ $ metadataFactory = new AttributeMetadataFactory ();
253+ $ metadata = $ metadataFactory ->metadata (Wrapper::class);
254+
255+ self ::assertCount (3 , $ metadata ->properties ());
256+
257+ $ propertyMetadata = $ metadata ->propertyForField ('value ' );
258+ self ::assertNull ($ propertyMetadata ->normalizer ());
259+
260+ $ propertyMetadata = $ metadata ->propertyForField ('object ' );
261+ self ::assertEquals (new ObjectNormalizer (Wrapper::class), $ propertyMetadata ->normalizer ());
262+
263+ $ propertyMetadata = $ metadata ->propertyForField ('scalar ' );
264+ self ::assertEquals (new ObjectNormalizer (Wrapper::class), $ propertyMetadata ->normalizer ());
265+ }
266+
236267 public function testExtends (): void
237268 {
238269 $ metadataFactory = new AttributeMetadataFactory ();
0 commit comments