|
18 | 18 | use Symfony\Component\Mailer\Transport\Smtp\Stream\AbstractStream;
|
19 | 19 | use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
|
20 | 20 | use Symfony\Component\Mime\Address;
|
| 21 | +use Symfony\Component\Mime\Email; |
| 22 | +use Symfony\Component\Mime\Exception\InvalidArgumentException; |
21 | 23 | use Symfony\Component\Mime\RawMessage;
|
22 | 24 |
|
23 | 25 | class SmtpTransportTest extends TestCase
|
@@ -86,6 +88,29 @@ public function testSendDoesPingAboveThreshold()
|
86 | 88 | $transport->send(new RawMessage('Message 3'), $envelope);
|
87 | 89 | $this->assertContains("NOOP\r\n", $stream->getCommands());
|
88 | 90 | }
|
| 91 | + |
| 92 | + public function testSendInvalidMessage() |
| 93 | + { |
| 94 | + $stream = new DummyStream(); |
| 95 | + |
| 96 | + $transport = new SmtpTransport($stream); |
| 97 | + $transport->setPingThreshold(1); |
| 98 | + |
| 99 | + $message = new Email(); |
| 100 | + $message->to('recipient@example.org'); |
| 101 | + $message->from('sender@example.org'); |
| 102 | + $message->attachFromPath('/does_not_exists'); |
| 103 | + |
| 104 | + try { |
| 105 | + $transport->send($message); |
| 106 | + $this->fail('Expected Symfony\Component\Mime\Exception\InvalidArgumentException to be thrown'); |
| 107 | + } catch (InvalidArgumentException $e) { |
| 108 | + $this->assertSame('Path "/does_not_exists" is not readable.', $e->getMessage()); |
| 109 | + } |
| 110 | + |
| 111 | + $this->assertNotContains("\r\n.\r\n", $stream->getCommands()); |
| 112 | + $this->assertTrue($stream->isClosed()); |
| 113 | + } |
89 | 114 | }
|
90 | 115 |
|
91 | 116 | class DummyStream extends AbstractStream
|
@@ -164,4 +189,10 @@ public function isClosed(): bool
|
164 | 189 | {
|
165 | 190 | return $this->closed;
|
166 | 191 | }
|
| 192 | + |
| 193 | + public function terminate(): void |
| 194 | + { |
| 195 | + parent::terminate(); |
| 196 | + $this->closed = true; |
| 197 | + } |
167 | 198 | }
|
0 commit comments