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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Mailer\Exception\HttpTransportException;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Contracts\HttpClient\ResponseInterface;

class ScalewayApiTransportTest extends TestCase
Expand Down Expand Up @@ -64,6 +65,10 @@ public function testSend()
$this->assertSame(['email' => '[email protected]', 'name' => 'Saif Eddin'], $body['to'][0]);
$this->assertSame('Hello!', $body['subject']);
$this->assertSame('Hello There!', $body['text']);
$this->assertCount(1, $body['attachments']);
$this->assertSame('attachment.txt', $body['attachments'][0]['name']);
$this->assertSame('text/plain', $body['attachments'][0]['type']);
$this->assertSame(base64_encode('some attachment'), $body['attachments'][0]['content']);

return new JsonMockResponse(['emails' => [['message_id' => 'foobar']]], [
'http_code' => 200,
Expand All @@ -76,7 +81,8 @@ public function testSend()
$mail->subject('Hello!')
->to(new Address('[email protected]', 'Saif Eddin'))
->from(new Address('[email protected]', 'Fabien'))
->text('Hello There!');
->text('Hello There!')
->addPart(new DataPart('some attachment', 'attachment.txt', 'text/plain'));

$message = $transport->send($mail);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function getPayload(Email $email, Envelope $envelope): array
$payload['html'] = $email->getHtmlBody();
}
if ($attachements = $this->prepareAttachments($email)) {
$payload['attachment'] = $attachements;
$payload['attachments'] = $attachements;
}

return $payload;
Expand All @@ -115,7 +115,7 @@ private function prepareAttachments(Email $email): array
$attachments[] = [
'name' => $filename,
'type' => $headers->get('Content-Type')->getBody(),
'content' => base64_encode($attachment->bodyToString()),
'content' => str_replace("\r\n", '', $attachment->bodyToString()),
];
}

Expand Down