Skip to content

[Mailer][Transport] Allow exception logging for RoundRobinTransport mailer #60110

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

Open
wants to merge 3 commits into
base: 7.4
Choose a base branch
from
Open
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
Prev Previous commit
Next Next commit
Add tests for logger property on RoundRobinTransport
  • Loading branch information
jnoordsij committed Apr 1, 2025
commit e93ae4fa8f34b73fc070ae0f10a280f218edde90
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Mailer\Tests\Transport;

use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Exception\TransportException;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\Transport\RoundRobinTransport;
Expand Down Expand Up @@ -144,19 +145,45 @@ public function testSendOneDeadAndRecoveryWithinRetryPeriod()
$this->assertTransports($t, 1, []);
}

public function testLoggerReceivesExceptions()
{
$t1 = $this->createMock(TransportInterface::class);
$t1->expects($this->exactly(2))->method('send');

$ex = new TransportException();
$t2 = $this->createMock(TransportInterface::class);
$t2->expects($this->exactly(1))
->method('send')
->willReturnCallback(fn () => throw $ex);
$t2->expects($this->atLeast(1))->method('__toString')->willReturn('t2');

$log = $this->createMock(LoggerInterface::class);
$log->expects($this->exactly(1))
->method('error')
->with('Transport "t2" failed.', ['exception' => $ex]);

$t = new RoundRobinTransport([$t1, $t2], logger: $log);
$p = new \ReflectionProperty($t, 'cursor');
$p->setValue($t, 0);
$t->send(new RawMessage(''));
$this->assertTransports($t, 1, []);
$t->send(new RawMessage(''));
$this->assertTransports($t, 1, [$t2]);
}

public function testFailureDebugInformation()
{
$t1 = $this->createMock(TransportInterface::class);
$e1 = new TransportException();
$e1->appendDebug('Debug message 1');
$t1->expects($this->once())->method('send')->willThrowException($e1);
$t1->expects($this->once())->method('__toString')->willReturn('t1');
$t1->expects($this->atLeast(1))->method('__toString')->willReturn('t1');

$t2 = $this->createMock(TransportInterface::class);
$e2 = new TransportException();
$e2->appendDebug('Debug message 2');
$t2->expects($this->once())->method('send')->willThrowException($e2);
$t2->expects($this->once())->method('__toString')->willReturn('t2');
$t2->expects($this->atLeast(1))->method('__toString')->willReturn('t2');

$t = new RoundRobinTransport([$t1, $t2]);

Expand Down