diff --git a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php index 7ec8313612049..2c8d91e9e4402 100644 --- a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php +++ b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Mailer\Envelope; +use Symfony\Component\Mailer\Exception\TransportException; use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport; use Symfony\Component\Mailer\Transport\Smtp\Stream\AbstractStream; use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream; @@ -43,6 +44,29 @@ public function testSendDoesNotPingBelowThreshold(): void $this->assertNotContains("NOOP\r\n", $stream->getCommands()); } + public function testSendPingAfterTransportException(): void + { + $stream = new DummyStream(); + $envelope = new Envelope(new Address('sender@example.org'), [new Address('recipient@example.org')]); + + $transport = new SmtpTransport($stream); + $transport->send(new RawMessage('Message 1'), $envelope); + $stream->close(); + $catch = false; + + try { + $transport->send(new RawMessage('Message 2'), $envelope); + } catch (TransportException $exception) { + $catch = true; + } + $this->assertTrue($catch); + $this->assertTrue($stream->isClosed()); + + $transport->send(new RawMessage('Message 3'), $envelope); + + $this->assertFalse($stream->isClosed()); + } + public function testSendDoesPingAboveThreshold(): void { $stream = new DummyStream(); @@ -76,13 +100,23 @@ class DummyStream extends AbstractStream */ private $commands; + /** + * @var bool + */ + private $closed = true; + public function initialize(): void { + $this->closed = false; $this->nextResponse = '220 localhost'; } public function write(string $bytes, $debug = true): void { + if ($this->closed) { + throw new TransportException('Unable to write bytes on the wire.'); + } + $this->commands[] = $bytes; if (0 === strpos($bytes, 'DATA')) { @@ -120,4 +154,14 @@ protected function getReadConnectionDescription(): string { return 'null'; } + + public function close(): void + { + $this->closed = true; + } + + public function isClosed(): bool + { + return $this->closed; + } } diff --git a/src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php b/src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php index 091b5e2bc5a60..26f2057f941ae 100644 --- a/src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php +++ b/src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php @@ -206,12 +206,11 @@ protected function doSend(SentMessage $message): void $this->stream->flush(); $this->executeCommand("\r\n.\r\n", [250]); $message->appendDebug($this->stream->getDebug()); + $this->lastMessageTime = microtime(true); } catch (TransportExceptionInterface $e) { $e->appendDebug($this->stream->getDebug()); - + $this->lastMessageTime = 0; throw $e; - } finally { - $this->lastMessageTime = microtime(true); } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy