Skip to content

Commit

Permalink
FIX: Refactor TestMailer to better be base class
Browse files Browse the repository at this point in the history
This small refactoring makes TestMailer better suited as a base class
for the behat-extension’s implementation, which means that we don’t
need to coordinate cross-module commits in dhensby’ SwiftMailer work.

See #6466
  • Loading branch information
Sam Minnee committed Jan 11, 2017
1 parent 747c077 commit 6fc50ca
Showing 1 changed file with 40 additions and 24 deletions.
64 changes: 40 additions & 24 deletions src/Dev/TestMailer.php
Expand Up @@ -22,18 +22,18 @@ class TestMailer extends Mailer
*/
public function sendPlain($to, $from, $subject, $plainContent, $attachedFiles = false, $customHeaders = false)
{
$this->emailsSent[] = array(
'type' => 'plain',
'to' => $to,
'from' => $from,
'subject' => $subject,
$this->saveEmail([
'Type' => 'plain',
'To' => $to,
'From' => $from,
'Subject' => $subject,

'content' => $plainContent,
'plainContent' => $plainContent,
'Content' => $plainContent,
'PlainContent' => $plainContent,

'attachedFiles' => $attachedFiles,
'customHeaders' => $customHeaders,
);
'AttachedFiles' => $attachedFiles,
'CustomHeaders' => $customHeaders,
]);

return true;
}
Expand Down Expand Up @@ -63,24 +63,33 @@ public function sendHTML(
$inlineImages = false
) {

$this->emailsSent[] = array(
'type' => 'html',
'to' => $to,
'from' => $from,
'subject' => $subject,
$this->saveEmail([
'Type' => 'html',
'To' => $to,
'From' => $from,
'Subject' => $subject,

'content' => $htmlContent,
'plainContent' => $plainContent,
'htmlContent' => $htmlContent,
'Content' => $htmlContent,
'PlainContent' => $plainContent,
'HtmlContent' => $htmlContent,

'attachedFiles' => $attachedFiles,
'customHeaders' => $customHeaders,
'inlineImages' => $inlineImages,
);
'AttachedFiles' => $attachedFiles,
'CustomHeaders' => $customHeaders,
'InlineImages' => $inlineImages,
]);

return true;
}

/**
* Save a single email to the log
* @param $data A map of information about the email
*/
protected function saveEmail($data)
{
$this->emailsSent[] = $data;
}

/**
* Clear the log of emails sent
*/
Expand All @@ -102,11 +111,18 @@ public function clearEmails()
*/
public function findEmail($to, $from = null, $subject = null, $content = null)
{
$compare = [
'To' => $to,
'From' => $from,
'Subject' => $subject,
'Content' => $content,
];

foreach ($this->emailsSent as $email) {
$matched = true;

foreach (array('to','from','subject','content') as $field) {
if ($value = $$field) {
foreach (array('To','From','Subject','Content') as $field) {
if ($value = $compare[$field]) {
if ($value[0] == '/') {
$matched = preg_match($value, $email[$field]);
} else {
Expand Down

0 comments on commit 6fc50ca

Please sign in to comment.