forked from captbaritone/codeception-mailcatcher-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,31 @@ public function grabUrlsFromLastEmail() | |
return $results; | ||
} | ||
|
||
/** | ||
* Grab Attachments From Email | ||
* | ||
* Returns array with the format [ [filename1 => bytes1], [filename2 => bytes2], ...] | ||
* | ||
* @return array | ||
* @author Marcelo Briones <[email protected]> | ||
*/ | ||
public function grabAttachmentsFromLastEmail() | ||
{ | ||
$email = $this->lastMessage(); | ||
|
||
$message = Message::from($email->getSource()); | ||
|
||
$attachments = []; | ||
|
||
foreach ($message->getAllAttachmentParts() as $attachmentPart) { | ||
$filename = $attachmentPart->getFilename(); | ||
$content = $attachmentPart->getContent(); | ||
$attachments[$filename] = $content; | ||
} | ||
|
||
return $attachments; | ||
} | ||
|
||
/** | ||
* See Attachment In Last Email | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,25 @@ public function test_grab_urls_from_last_email_with_encoding( | |
$I->assertEquals($example[0], $urls[0]); | ||
} | ||
|
||
/** | ||
* @param AcceptanceTester $I | ||
*/ | ||
public function test_grab_attachments_from_last(AcceptanceTester $I) | ||
{ | ||
$user = "[email protected]"; | ||
|
||
$attachments = [ | ||
"image.jpg" => codecept_data_dir('image.jpg'), | ||
"lorem.txt" => codecept_data_dir('lorem.txt'), | ||
"compressed.zip" => codecept_data_dir('compressed.zip'), | ||
]; | ||
|
||
$I->sendEmail($user, 'Email with attachments', "I have attachments.", null, $attachments); | ||
$grabbedAttachments = $I->grabAttachmentsFromLastEmail(); | ||
|
||
$I->assertEquals(3, count($grabbedAttachments)); | ||
} | ||
|
||
/** | ||
* @param AcceptanceTester $I | ||
*/ | ||
|