Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public function supports(MessageInterface $message): bool
*/
protected function doSend(MessageInterface $message): SentMessage
{
if (!$this->supports($message)) {
if (!$message instanceof SmsMessage) {
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
}

$email = (new Email())
->from($message->getFrom() ?: $this->from)
->from($this->from)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain this change? it looks suspicious to me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petski Any insight?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks valid to me. At least, there is nothing indicating that the $from property of the SmsMessage class has to be a valid e-mail address and thus we IMO must not use it as such in the FakeSmsEmailTransport.

->to($this->to)
->subject(sprintf('New SMS on phone number: %s', $message->getPhone()))
->subject('New SMS to phone number ' . $message->getPhone() . ($message->getFrom() ? ' from ' . $message->getFrom() : ''))
->html($message->getSubject())
->text($message->getSubject());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function supports(MessageInterface $message): bool
*/
protected function doSend(MessageInterface $message): SentMessage
{
if (!$this->supports($message)) {
if (!$message instanceof SmsMessage) {
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
}

$this->logger->info(sprintf('New SMS on phone number: %s', $message->getPhone()));
$this->logger->info('New SMS to phone number ' . $message->getPhone() . ($message->getFrom() ? ' from ' . $message->getFrom() : ''));

return new SentMessage($message, (string) $this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,30 @@ public function testSendWithDefaultTransport()
$this->assertInstanceOf(Email::class, $sentEmail);
$this->assertSame($to, $sentEmail->getTo()[0]->getEncodedAddress());
$this->assertSame($from, $sentEmail->getFrom()[0]->getEncodedAddress());
$this->assertSame(sprintf('New SMS on phone number: %s', $phone), $sentEmail->getSubject());
$this->assertSame(\sprintf('New SMS to phone number %s', $phone), $sentEmail->getSubject());
$this->assertSame($subject, $sentEmail->getTextBody());
$this->assertFalse($sentEmail->getHeaders()->has('X-Transport'));
}

public function testSendWithFrom()
{
$transportName = null;

$message = new SmsMessage($phone = '0611223344', $subject = 'Hello!', $fromPhone = '0655667788');

$mailer = new DummyMailer();

$transport = (new FakeSmsEmailTransport($mailer, $to = '[email protected]', $from = '[email protected]'));
$transport->setHost($transportName);

$transport->send($message);

/** @var Email $sentEmail */
$sentEmail = $mailer->getSentEmail();
$this->assertInstanceOf(Email::class, $sentEmail);
$this->assertSame($to, $sentEmail->getTo()[0]->getEncodedAddress());
$this->assertSame($from, $sentEmail->getFrom()[0]->getEncodedAddress());
$this->assertSame(\sprintf('New SMS to phone number %s from %s', $phone, $fromPhone), $sentEmail->getSubject());
$this->assertSame($subject, $sentEmail->getTextBody());
$this->assertFalse($sentEmail->getHeaders()->has('X-Transport'));
}
Expand All @@ -93,7 +116,7 @@ public function testSendWithCustomTransport()
$this->assertInstanceOf(Email::class, $sentEmail);
$this->assertSame($to, $sentEmail->getTo()[0]->getEncodedAddress());
$this->assertSame($from, $sentEmail->getFrom()[0]->getEncodedAddress());
$this->assertSame(sprintf('New SMS on phone number: %s', $phone), $sentEmail->getSubject());
$this->assertSame(\sprintf('New SMS to phone number %s', $phone), $sentEmail->getSubject());
$this->assertSame($subject, $sentEmail->getTextBody());
$this->assertTrue($sentEmail->getHeaders()->has('X-Transport'));
$this->assertSame($transportName, $sentEmail->getHeaders()->get('X-Transport')->getBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testSendWithDefaultTransport()
$this->assertNotEmpty($logs);

$log = $logs[0];
$this->assertSame(sprintf('New SMS on phone number: %s', $phone), $log['message']);
$this->assertSame(\sprintf('New SMS to phone number %s', $phone), $log['message']);
$this->assertSame('info', $log['level']);
}
}
Loading