Skip to content

Commit

Permalink
Add further assertions when testing multipart alternative messages
Browse files Browse the repository at this point in the history
This change adds a series of assertions for attachments on
multipart/alternative messages, to help verify that they contain what
they're expected to contain. I felt that it was helpful to have
assertions for attachments (or non text/HTML content) as well, so that
more of the code could be properly tested.

Signed-off-by: Matthew Setter <matthew@matthewsetter.com>
  • Loading branch information
settermjd committed Nov 23, 2023
1 parent ee273da commit 06f3ab8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,5 +401,31 @@ public function testDecodeMultipartMimeMessageWithMessagePartAlternatives()
"application/vnd.openxmlformats-officedocument.wordprocessingml.document;\r\n name=\"DockMcWordface.docx\"",
$headers->get('Content-Type')->getFieldValue()
);

$attachments = array_filter($parts, function ($part, $index) {
return str_starts_with(
(string) $part->getDisposition(),
"attachment"
);
}, ARRAY_FILTER_USE_BOTH);
$this->assertCount(1, $attachments);

$nonAttachments = array_filter($parts, function ($part, $index) {
return ! str_starts_with(
(string) $part->getDisposition(),
"attachment"
);
}, ARRAY_FILTER_USE_BOTH);
$this->assertCount(1, $nonAttachments);
$this->assertCount(2, $nonAttachments[0]->getParts());

/** @var Part[] $noteParts */
$noteParts = array_filter($nonAttachments[0]->getParts(), function ($part, $index) {
return str_starts_with(
(string) $part->getType(),
"text/plain"
);
}, ARRAY_FILTER_USE_BOTH);
$this->assertSame("This is a test email with 1 attachment.", trim($noteParts[0]->getContent()));
}
}

0 comments on commit 06f3ab8

Please sign in to comment.