2020use Symfony \Component \Serializer \Normalizer \MimeMessageNormalizer ;
2121use Symfony \Component \Serializer \Normalizer \ObjectNormalizer ;
2222use Symfony \Component \Serializer \Normalizer \PropertyNormalizer ;
23+ use Symfony \Component \Serializer \Normalizer \TranslatableNormalizer ;
2324use Symfony \Component \Serializer \Serializer ;
25+ use Symfony \Component \Translation \IdentityTranslator ;
26+ use Symfony \Component \Translation \TranslatableMessage ;
2427
2528class TemplatedEmailTest extends TestCase
2629{
@@ -44,19 +47,22 @@ public function testSerialize()
4447 ->htmlTemplate ('text.html.twig ' )
4548 ->context ($ context = ['a ' => 'b ' ])
4649 ->locale ($ locale = 'fr_FR ' )
50+ ->subject ($ subject = new TranslatableMessage ('hello {{ name }} ' , ['name ' => 'John ' ], 'greetings ' ))
4751 ;
4852
4953 $ email = unserialize (serialize ($ email ));
5054 $ this ->assertEquals ('text.txt.twig ' , $ email ->getTextTemplate ());
5155 $ this ->assertEquals ('text.html.twig ' , $ email ->getHtmlTemplate ());
5256 $ this ->assertEquals ($ context , $ email ->getContext ());
5357 $ this ->assertEquals ($ locale , $ email ->getLocale ());
58+ $ this ->assertEquals ($ subject , $ email ->getTranslatableSubject ());
5459 }
5560
5661 public function testSymfonySerialize ()
5762 {
5863 // we don't add from/sender to check that validation is not triggered to serialize an email
5964 $ e = new TemplatedEmail ();
65+ $ e ->subject (new TranslatableMessage ('hello.world ' ));
60666167 $ e ->textTemplate ('email.txt.twig ' );
6268 $ e ->htmlTemplate ('email.html.twig ' );
@@ -67,6 +73,7 @@ public function testSymfonySerialize()
6773
6874 $ expectedJson = <<<EOF
6975{
76+ "subject": "hello.world",
7077 "htmlTemplate": "email.html.twig",
7178 "textTemplate": "email.txt.twig",
7279 "locale": "en",
@@ -84,6 +91,15 @@ public function testSymfonySerialize()
8491 }
8592 ],
8693 "headers": {
94+ "subject": [
95+ {
96+ "value": "hello.world",
97+ "name": "Subject",
98+ "lineLength": 76,
99+ "lang": null,
100+ "charset": "utf-8"
101+ }
102+ ],
87103 "to": [
88104 {
89105 "addresses": [
@@ -108,6 +124,7 @@ public function testSymfonySerialize()
108124 $ serializer = new Serializer ([
109125 new ArrayDenormalizer (),
110126 new MimeMessageNormalizer ($ propertyNormalizer ),
127+ new TranslatableNormalizer (new IdentityTranslator ()),
111128 new ObjectNormalizer (null , null , null , $ extractor ),
112129 $ propertyNormalizer ,
113130 ], [new JsonEncoder ()]);
0 commit comments