$this->
assertStringMatchesFormat($expected,
str_replace("\r\n", "\n",
implode('',
iterator_to_array($message->
toIterable(), false
))));
} public function testSymfonySerialize() { // we don't add from/sender to check that it's not needed to serialize an email
$body =
new MixedPart( new AlternativePart( new TextPart('Text content'
),
new TextPart('HTML content', 'utf-8', 'html'
) ),
new DataPart('text data', 'text.txt'
) );
$body->
getHeaders()->
addHeader('foo', 'bar'
);
$e =
new Message((new Headers())->
addMailboxListHeader('To',
['you@example.com'
]),
$body);
$expected =
clone $e;
$expectedJson = <<<EOF
{
"headers": {
"to": [
{
"addresses": [
{
"address": "you@example.com",
"name": ""
}
],
"name": "To",
"lineLength": 76,
"lang": null,
"charset": "utf-8"
}
]
},
"body": {
"boundary": null,
"parts": [
{
"boundary": null,
"parts": [
{
"body": "Text content",
"charset": "utf-8",
"subtype": "plain",
"disposition": null,
"name": null,
"encoding": "quoted-printable",%A
"headers": [],
"class": "Symfony\\\\Component\\\\Mime\\\\Part\\\TextPart"
},
{
"body": "HTML content",
"charset": "utf-8",
"subtype": "html",
"disposition": null,
"name": null,
"encoding": "quoted-printable",%A
"headers": [],
"class": "Symfony\\\\Component\\\\Mime\\\\Part\\\\TextPart"
}
],
"headers": [],
"class": "Symfony\\\\Component\\\\Mime\\\\Part\\\\Multipart\\\\AlternativePart"
},
{
"filename": "text.txt",
"mediaType": "application",%A
"body": "text data",
"charset": null,
"subtype": "octet-stream",
"disposition": "attachment",
"name": "text.txt",
"encoding": "base64",%A
"headers": [],
"class": "Symfony\\\\Component\\\\Mime\\\\Part\\\\DataPart"
}
],
"headers": {
"foo": [
{
"value": "bar",
"name": "foo",
"lineLength": 76,
"lang": null,
"charset": "utf-8"
}
]
},
"class": "Symfony\\\\Component\\\\Mime\\\\Part\\\\Multipart\\\\MixedPart"
},
"message": null
}