Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 40b3351

Browse files
author
Kristof Hejj
committed
Add a dedicated test
1 parent 8958280 commit 40b3351

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/Symfony/Component/Mime/Tests/EmailTest.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\Mime\Part\Multipart\RelatedPart;
2424
use Symfony\Component\Mime\Part\TextPart;
2525
use Symfony\Component\Mime\Test\Constraint\EmailHeaderSame;
26+
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
2627
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
2728
use Symfony\Component\Serializer\Encoder\JsonEncoder;
2829
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
@@ -569,7 +570,7 @@ public function testSymfonySerialize()
569570
}
570571
EOF;
571572

572-
$extractor = new ReflectionExtractor();
573+
$extractor = new PhpDocExtractor();
573574
$propertyNormalizer = new PropertyNormalizer(null, null, $extractor);
574575
$serializer = new Serializer([
575576
new ArrayDenormalizer(),
@@ -591,6 +592,40 @@ public function testSymfonySerialize()
591592
$this->assertEquals($expected->getBody(), $n->getBody());
592593
}
593594

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+
594629
public function testMissingHeaderDoesNotThrowError()
595630
{
596631
$this->expectException(ExpectationFailedException::class);

0 commit comments

Comments
 (0)