|
12 | 12 | namespace Symfony\Component\Mailer\Tests\Transport; |
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase; |
| 15 | +use Psr\Log\LoggerInterface; |
15 | 16 | use Symfony\Component\Mailer\Exception\TransportException; |
16 | 17 | use Symfony\Component\Mailer\Exception\TransportExceptionInterface; |
17 | 18 | use Symfony\Component\Mailer\Transport\RoundRobinTransport; |
@@ -167,19 +168,45 @@ public function testSendOneDeadMessageAlterationsDoNotPersist() |
167 | 168 | $this->assertFalse($message->getHeaders()->has('X-Transport-1')); |
168 | 169 | } |
169 | 170 |
|
| 171 | + public function testLoggerReceivesExceptions() |
| 172 | + { |
| 173 | + $t1 = $this->createMock(TransportInterface::class); |
| 174 | + $t1->expects($this->exactly(2))->method('send'); |
| 175 | + |
| 176 | + $ex = new TransportException(); |
| 177 | + $t2 = $this->createMock(TransportInterface::class); |
| 178 | + $t2->expects($this->exactly(1)) |
| 179 | + ->method('send') |
| 180 | + ->willReturnCallback(fn () => throw $ex); |
| 181 | + $t2->expects($this->atLeast(1))->method('__toString')->willReturn('t2'); |
| 182 | + |
| 183 | + $log = $this->createMock(LoggerInterface::class); |
| 184 | + $log->expects($this->exactly(1)) |
| 185 | + ->method('error') |
| 186 | + ->with('Transport "t2" failed.', ['exception' => $ex]); |
| 187 | + |
| 188 | + $t = new RoundRobinTransport([$t1, $t2], logger: $log); |
| 189 | + $p = new \ReflectionProperty($t, 'cursor'); |
| 190 | + $p->setValue($t, 0); |
| 191 | + $t->send(new RawMessage('')); |
| 192 | + $this->assertTransports($t, 1, []); |
| 193 | + $t->send(new RawMessage('')); |
| 194 | + $this->assertTransports($t, 1, [$t2]); |
| 195 | + } |
| 196 | + |
170 | 197 | public function testFailureDebugInformation() |
171 | 198 | { |
172 | 199 | $t1 = $this->createMock(TransportInterface::class); |
173 | 200 | $e1 = new TransportException(); |
174 | 201 | $e1->appendDebug('Debug message 1'); |
175 | 202 | $t1->expects($this->once())->method('send')->willThrowException($e1); |
176 | | - $t1->expects($this->once())->method('__toString')->willReturn('t1'); |
| 203 | + $t1->expects($this->atLeast(1))->method('__toString')->willReturn('t1'); |
177 | 204 |
|
178 | 205 | $t2 = $this->createMock(TransportInterface::class); |
179 | 206 | $e2 = new TransportException(); |
180 | 207 | $e2->appendDebug('Debug message 2'); |
181 | 208 | $t2->expects($this->once())->method('send')->willThrowException($e2); |
182 | | - $t2->expects($this->once())->method('__toString')->willReturn('t2'); |
| 209 | + $t2->expects($this->atLeast(1))->method('__toString')->willReturn('t2'); |
183 | 210 |
|
184 | 211 | $t = new RoundRobinTransport([$t1, $t2]); |
185 | 212 |
|
|
0 commit comments