|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\Mailer\Exception\TransportException;
|
| 16 | +use Symfony\Component\Mailer\Exception\TransportExceptionInterface; |
16 | 17 | use Symfony\Component\Mailer\Transport\RoundRobinTransport;
|
17 | 18 | use Symfony\Component\Mailer\Transport\TransportInterface;
|
18 | 19 | use Symfony\Component\Mime\RawMessage;
|
@@ -60,10 +61,21 @@ public function testSendAllDead()
|
60 | 61 | $t2 = $this->createMock(TransportInterface::class);
|
61 | 62 | $t2->expects($this->once())->method('send')->will($this->throwException(new TransportException()));
|
62 | 63 | $t = new RoundRobinTransport([$t1, $t2]);
|
63 |
| - $this->expectException(TransportException::class); |
64 |
| - $this->expectExceptionMessage('All transports failed.'); |
65 |
| - $t->send(new RawMessage('')); |
66 |
| - $this->assertTransports($t, 1, [$t1, $t2]); |
| 64 | + $p = new \ReflectionProperty($t, 'cursor'); |
| 65 | + $p->setAccessible(true); |
| 66 | + $p->setValue($t, 0); |
| 67 | + |
| 68 | + try { |
| 69 | + $t->send(new RawMessage('')); |
| 70 | + } catch (\Exception $e) { |
| 71 | + $this->assertInstanceOf(TransportException::class, $e); |
| 72 | + $this->assertStringContainsString('All transports failed.', $e->getMessage()); |
| 73 | + $this->assertTransports($t, 0, [$t1, $t2]); |
| 74 | + |
| 75 | + return; |
| 76 | + } |
| 77 | + |
| 78 | + $this->fail('The expected exception was not thrown.'); |
67 | 79 | }
|
68 | 80 |
|
69 | 81 | public function testSendOneDead()
|
@@ -127,6 +139,34 @@ public function testSendOneDeadAndRecoveryWithinRetryPeriod()
|
127 | 139 | $this->assertTransports($t, 1, []);
|
128 | 140 | }
|
129 | 141 |
|
| 142 | + public function testFailureDebugInformation() |
| 143 | + { |
| 144 | + $t1 = $this->createMock(TransportInterface::class); |
| 145 | + $e1 = new TransportException(); |
| 146 | + $e1->appendDebug('Debug message 1'); |
| 147 | + $t1->expects($this->once())->method('send')->will($this->throwException($e1)); |
| 148 | + $t1->expects($this->once())->method('__toString')->willReturn('t1'); |
| 149 | + |
| 150 | + $t2 = $this->createMock(TransportInterface::class); |
| 151 | + $e2 = new TransportException(); |
| 152 | + $e2->appendDebug('Debug message 2'); |
| 153 | + $t2->expects($this->once())->method('send')->will($this->throwException($e2)); |
| 154 | + $t2->expects($this->once())->method('__toString')->willReturn('t2'); |
| 155 | + |
| 156 | + $t = new RoundRobinTransport([$t1, $t2]); |
| 157 | + |
| 158 | + try { |
| 159 | + $t->send(new RawMessage('')); |
| 160 | + } catch (TransportExceptionInterface $e) { |
| 161 | + $this->assertStringContainsString('Transport "t1": Debug message 1', $e->getDebug()); |
| 162 | + $this->assertStringContainsString('Transport "t2": Debug message 2', $e->getDebug()); |
| 163 | + |
| 164 | + return; |
| 165 | + } |
| 166 | + |
| 167 | + $this->fail('Expected exception was not thrown!'); |
| 168 | + } |
| 169 | + |
130 | 170 | private function assertTransports(RoundRobinTransport $transport, int $cursor, array $deadTransports)
|
131 | 171 | {
|
132 | 172 | $p = new \ReflectionProperty($transport, 'cursor');
|
|
0 commit comments