Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix return value for single email address of Message::normalizeEmail() #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public function getBcc()
public function sender($email, $name = null)
{
$emails = $this->normalizeEmail($email);
$emails = is_array($email) ? $email : [$emails];

foreach ($emails as $email) {
$this->getMessage()->setSender($email, $name);
Expand Down Expand Up @@ -843,7 +844,7 @@ protected function createEmbedViaData($data, $name = null)
*
* @param string|array|\Traversable $email
*
* @return array
* @return string|array
*/
protected function normalizeEmail($email)
{
Expand All @@ -862,8 +863,7 @@ protected function normalizeEmail($email)

return $emails;
} else {
$emails[] = $this->getManager()->normalizeEmail($email);
return $emails;
return $this->getManager()->normalizeEmail($email);
}
}
}
65 changes: 65 additions & 0 deletions tests/functional/ManagerSMTPCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,69 @@ public function mailerManagerCreateMessageFromView(FunctionalTester $I)
$I->assertEquals($body, $mail->Content->Body);
$I->assertStringContainsString('Subject: ' . $subject, $mail->Raw->Data);
}

public function mailerManagerCreateMessageWithName(FunctionalTester $I)
{
$sender = '[email protected]';
$name = 'Example Name';
$from = '[email protected]';
$to = '[email protected]';
$subject = 'Hello SMTP';
$body = 'Lorem Ipsum';

$mailer = new Manager($this->config);

$message = $mailer->createMessage()
->sender($sender, $name)
->from($from, $name)
->to($to, $name)
->subject($subject)
->content($body);

$message->send();

$opts = [
'http' => [
'method' => 'GET',
'header' => 'Accept-language: en\r\n'
]
];

$context = stream_context_create($opts);

// Get all mail send in the MailHog SMTP
$dataMail = file_get_contents($this->baseUrl . 'messages', false, $context);
$dataMail = \json_decode($dataMail);

//Check that there are one mail send
$I->assertCount(3, $dataMail);

$mail = $dataMail[0];

$mailFromData = $mail->From;
$mailToData = end($mail->To);

$mailFrom = $mailFromData->Mailbox . '@' . $mailFromData->Domain;
$mailTo = $mailToData->Mailbox . '@' . $mailToData->Domain;

$I->assertEquals($sender, $mailFrom);
$I->assertEquals($to, $mailTo);

$headers = $mail->Content->Headers;

$mailSenderWithName = end($headers->Sender);
$senderWithName = sprintf('%s <%s>', $name, $sender);
$I->assertEquals($senderWithName, $mailSenderWithName);

$mailFromWithName = end($headers->From);
$fromWithName = sprintf('%s <%s>', $name, $from);
$I->assertEquals($fromWithName, $mailFromWithName);

$mailToWithName = end($headers->To);
$toWithName = sprintf('%s <%s>', $name, $to);
$I->assertEquals($toWithName, $mailToWithName);

$I->assertEquals($body, $mail->Content->Body);
$I->assertStringContainsString('Subject: ' . $subject, $mail->Raw->Data);
}
}