23
23
use Symfony \Component \Mime \Part \Multipart \RelatedPart ;
24
24
use Symfony \Component \Mime \Part \TextPart ;
25
25
use Symfony \Component \Mime \Test \Constraint \EmailHeaderSame ;
26
+ use Symfony \Component \PropertyInfo \Extractor \PhpDocExtractor ;
26
27
use Symfony \Component \PropertyInfo \Extractor \ReflectionExtractor ;
27
28
use Symfony \Component \Serializer \Encoder \JsonEncoder ;
28
29
use Symfony \Component \Serializer \Normalizer \ArrayDenormalizer ;
@@ -569,7 +570,7 @@ public function testSymfonySerialize()
569
570
}
570
571
EOF ;
571
572
572
- $ extractor = new ReflectionExtractor ();
573
+ $ extractor = new PhpDocExtractor ();
573
574
$ propertyNormalizer = new PropertyNormalizer (null , null , $ extractor );
574
575
$ serializer = new Serializer ([
575
576
new ArrayDenormalizer (),
@@ -591,6 +592,40 @@ public function testSymfonySerialize()
591
592
$ this ->assertEquals ($ expected ->getBody (), $ n ->getBody ());
592
593
}
593
594
595
+ public function testSymfonySerialize2 ()
596
+ {
597
+ $ e = new Email ();
598
+ $ expected = clone $ e ;
599
+
600
+ $ expectedJson = <<<EOF
601
+ {
602
+ "text": null,
603
+ "textCharset": null,
604
+ "html": null,
605
+ "htmlCharset": null,
606
+ "attachments": [],
607
+ "headers": [],
608
+ "body": null,
609
+ "message": null
610
+ }
611
+ EOF ;
612
+
613
+ $ extractor = new ReflectionExtractor ();
614
+ $ propertyNormalizer = new PropertyNormalizer (null , null , $ extractor );
615
+ $ serializer = new Serializer ([
616
+ new ArrayDenormalizer (),
617
+ new MimeMessageNormalizer ($ propertyNormalizer ),
618
+ new ObjectNormalizer (null , null , null , $ extractor ),
619
+ $ propertyNormalizer ,
620
+ ], [new JsonEncoder ()]);
621
+
622
+ $ serialized = $ serializer ->serialize ($ e , 'json ' , [ObjectNormalizer::IGNORED_ATTRIBUTES => ['cachedBody ' ]]);
623
+ $ this ->assertSame ($ expectedJson , json_encode (json_decode ($ serialized ), \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES ));
624
+
625
+ $ n = $ serializer ->deserialize ($ serialized , Email::class, 'json ' );
626
+ $ this ->assertEquals ($ expected , $ n );
627
+ }
628
+
594
629
public function testMissingHeaderDoesNotThrowError ()
595
630
{
596
631
$ this ->expectException (ExpectationFailedException::class);
0 commit comments