From 4db9d9bb6390df783bcfd51a76836b763f4f0b05 Mon Sep 17 00:00:00 2001 From: Pawel Wasiluk <45973917+Pavlico@users.noreply.github.com> Date: Thu, 21 Oct 2021 08:09:13 +0200 Subject: [PATCH] Added tests and method for adding content with string (#797) --- src/Message/MessageBuilder.php | 14 ++++++++++++++ tests/Message/MessageBuilderTest.php | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Message/MessageBuilder.php b/src/Message/MessageBuilder.php index 5182202..8f7522a 100644 --- a/src/Message/MessageBuilder.php +++ b/src/Message/MessageBuilder.php @@ -278,6 +278,20 @@ class MessageBuilder return $this; } + public function addStringAttachment(string $attachmentContent, string $attachmentName = null): self + { + if (!isset($this->message['attachment'])) { + $this->message['attachment'] = []; + } + + $this->message['attachment'][] = [ + 'fileContent' => $attachmentContent, + 'filename' => $attachmentName, + ]; + + return $this; + } + public function addInlineImage(string $inlineImagePath, string $inlineImageName = null): self { if (!isset($this->message['inline'])) { diff --git a/tests/Message/MessageBuilderTest.php b/tests/Message/MessageBuilderTest.php index 5e32ade..4ac44ee 100644 --- a/tests/Message/MessageBuilderTest.php +++ b/tests/Message/MessageBuilderTest.php @@ -161,6 +161,26 @@ class MessageBuilderTest extends MailgunTestCase ); } + public function testAddStringAttachment() + { + $this->messageBuilder->addStringAttachment('12345'); + $this->messageBuilder->addStringAttachment('test'); + $message = $this->messageBuilder->getMessage(); + $this->assertEquals( + [ + [ + 'fileContent' => '12345', + 'filename' => null, + ], + [ + 'fileContent' => 'test', + 'filename' => null, + ], + ], + $message['attachment'] + ); + } + public function testAddInlineImages() { $this->messageBuilder->addInlineImage('@../TestAssets/mailgun_icon.png');