|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\Mailer\Envelope;
|
| 16 | +use Symfony\Component\Mailer\Exception\TransportException; |
16 | 17 | use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport;
|
17 | 18 | use Symfony\Component\Mailer\Transport\Smtp\Stream\AbstractStream;
|
18 | 19 | use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
|
@@ -43,6 +44,29 @@ public function testSendDoesNotPingBelowThreshold(): void
|
43 | 44 | $this->assertNotContains("NOOP\r\n", $stream->getCommands());
|
44 | 45 | }
|
45 | 46 |
|
| 47 | + public function testSendPingAfterTransportException(): void |
| 48 | + { |
| 49 | + $stream = new DummyStream(); |
| 50 | + $envelope = new Envelope( new Address( '[email protected]'), [ new Address( '[email protected]')]); |
| 51 | + |
| 52 | + $transport = new SmtpTransport($stream); |
| 53 | + $transport->send(new RawMessage('Message 1'), $envelope); |
| 54 | + $stream->close(); |
| 55 | + $catch = false; |
| 56 | + |
| 57 | + try { |
| 58 | + $transport->send(new RawMessage('Message 2'), $envelope); |
| 59 | + } catch (TransportException $exception) { |
| 60 | + $catch = true; |
| 61 | + } |
| 62 | + $this->assertTrue($catch); |
| 63 | + $this->assertTrue($stream->isClosed()); |
| 64 | + |
| 65 | + $transport->send(new RawMessage('Message 3'), $envelope); |
| 66 | + |
| 67 | + $this->assertFalse($stream->isClosed()); |
| 68 | + } |
| 69 | + |
46 | 70 | public function testSendDoesPingAboveThreshold(): void
|
47 | 71 | {
|
48 | 72 | $stream = new DummyStream();
|
@@ -76,13 +100,23 @@ class DummyStream extends AbstractStream
|
76 | 100 | */
|
77 | 101 | private $commands;
|
78 | 102 |
|
| 103 | + /** |
| 104 | + * @var bool |
| 105 | + */ |
| 106 | + private $closed = true; |
| 107 | + |
79 | 108 | public function initialize(): void
|
80 | 109 | {
|
| 110 | + $this->closed = false; |
81 | 111 | $this->nextResponse = '220 localhost';
|
82 | 112 | }
|
83 | 113 |
|
84 | 114 | public function write(string $bytes, $debug = true): void
|
85 | 115 | {
|
| 116 | + if ($this->closed) { |
| 117 | + throw new TransportException('Unable to write bytes on the wire.'); |
| 118 | + } |
| 119 | + |
86 | 120 | $this->commands[] = $bytes;
|
87 | 121 |
|
88 | 122 | if (0 === strpos($bytes, 'DATA')) {
|
@@ -120,4 +154,14 @@ protected function getReadConnectionDescription(): string
|
120 | 154 | {
|
121 | 155 | return 'null';
|
122 | 156 | }
|
| 157 | + |
| 158 | + public function close(): void |
| 159 | + { |
| 160 | + $this->closed = true; |
| 161 | + } |
| 162 | + |
| 163 | + public function isClosed(): bool |
| 164 | + { |
| 165 | + return $this->closed; |
| 166 | + } |
123 | 167 | }
|
0 commit comments