33namespace Tests \Tempest \Integration \Mapper ;
44
55use PHPUnit \Framework \Attributes \Test ;
6+ use PHPUnit \Framework \Attributes \TestWith ;
67use Tempest \Core \Priority ;
78use Tempest \Mapper ;
89use Tests \Tempest \Fixtures \Modules \Books \Models \Author ;
@@ -25,30 +26,34 @@ public function fallbacks_to_default_context(): void
2526 }
2627
2728 #[Test]
28- public function uses_serializers_from_given_context (): void
29+ #[TestWith(['custom ' ], name: 'string ' )]
30+ #[TestWith([TestMapperContextEnum::VALUE ], name: 'enum ' )]
31+ public function uses_serializers_from_given_context (mixed $ context ): void
2932 {
3033 $ author = new Author (
3134 name: 'test ' ,
3235 );
3336
3437 $ factory = $ this ->container ->get (Mapper \SerializerFactory::class);
35- $ factory ->addSerializer ('string ' , CustomStringSerializer::class, context: ' custom ' , priority: Priority::HIGHEST );
38+ $ factory ->addSerializer ('string ' , CustomStringSerializer::class, context: $ context , priority: Priority::HIGHEST );
3639
3740 $ serialized = Mapper \map ($ author )
38- ->in (' custom ' )
41+ ->in ($ context )
3942 ->toJson ();
4043
4144 $ this ->assertSame ('{"name":"{\"type\":\"string\",\"value\":\"test\"}","type":"a","books":[],"publisher":null,"id":null} ' , $ serialized );
4245 }
4346
4447 #[Test]
45- public function uses_casters_from_given_context (): void
48+ #[TestWith(['custom ' ], name: 'string ' )]
49+ #[TestWith([TestMapperContextEnum::VALUE ], name: 'enum ' )]
50+ public function uses_casters_from_given_context (mixed $ context ): void
4651 {
4752 $ factory = $ this ->container ->get (Mapper \CasterFactory::class);
48- $ factory ->addCaster ('string ' , CustomStringSerializer::class, context: ' custom ' );
53+ $ factory ->addCaster ('string ' , CustomStringSerializer::class, context: $ context );
4954
5055 $ author = Mapper \make (Author::class)
51- ->in (' custom ' )
56+ ->in ($ context )
5257 ->from ('{"name":"{\"type\":\"string\",\"value\":\"test\"}","type":"a","books":[],"publisher":null,"id":1} ' );
5358
5459 $ this ->assertInstanceOf (Author::class, $ author );
@@ -76,3 +81,8 @@ public function cast(mixed $input): mixed
7681 return $ data ['value ' ] ?? null ;
7782 }
7883}
84+
85+ enum TestMapperContextEnum: string
86+ {
87+ case VALUE = 'value ' ;
88+ }
0 commit comments