10000 [Mailer] Return `SentMessage` from `Mailer::send` if available by pableu · Pull Request #38517 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer] Return SentMessage from Mailer::send if available #38517

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

Closed
wants to merge 2 commits into from
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
1 change: 1 addition & 0 deletions src/Symfony/Component/Mailer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* added `NativeTransportFactory` to configure a transport based on php.ini settings
* added `local_domain`, `restart_threshold`, `restart_threshold_sleep` and `ping_threshold` options for `smtp`
* added `command` option for `sendmail`
* return `SentMessage` after `Mailer::send` if not using messenger and available from transport

4.4.0
-----
Expand Down
6 changes: 2 additions & 4 deletions src/Symfony/Component/Mailer/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ public function __construct(TransportInterface $transport, MessageBusInterface $
$this->dispatcher = class_exists(Event::class) ? LegacyEventDispatcherProxy::decorate($dispatcher) : $dispatcher;
}

public function send(RawMessage $message, Envelope $envelope = null): void
public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
{
if (null === $this->bus) {
$this->transport->send($message, $envelope);

return;
return $this->transport->send($message, $envelope);
}

if (null !== $this->dispatcher) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mailer/MailerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ interface MailerInterface
/**
* @throws TransportExceptionInterface
*/
public function send(RawMessage $message, Envelope $envelope = null): void;
public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage;
Copy link
Member

Choose a reason for hiding this comment

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

This is a BC break and must be reverted. :/

}
15 changes: 14 additions & 1 deletion src/Symfony/Component/Mailer/Tests/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,31 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\Exception\LogicException;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Mime\RawMessage;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

class MailerTest extends TestCase
{
public function testSendingRawMessages()
public function testSendingRawMessagesWithMessenger()
{
$this->expectException(LogicException::class);

$transport = new Mailer($this->createMock(TransportInterface::class), $this->createMock(MessageBusInterface::class), $this->createMock(EventDispatcherInterface::class));
$transport->send(new RawMessage('Some raw email message'));
}

public function testSendingRawMessagesWithoutMessenger()
{
$transportMock = $this->createMock(TransportInterface::class);
$transportMock
->expects(self::once())
->method('send')
->willReturn($this->createMock(SentMessage::class));
$transport = new Mailer($transportMock, null, $this->createMock(EventDispatcherInterface::class));
$result = $transport->send(new RawMessage('Some raw email message without messenger'));
self::assertInstanceOf(SentMessage::class, $result);
}
}
0