Added tests and method for adding content with string (#797)

This commit is contained in:
Pawel Wasiluk 2021-10-21 08:09:13 +02:00 committed by GitHub
parent d926ba72fd
commit 4db9d9bb63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -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'])) {

View File

@ -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');