Force ping after transport Exception
This commit is contained in:
parent
0506f8ce2b
commit
7ccbef62f6
@ -13,6 +13,7 @@ namespace Symfony\Component\Mailer\Tests\Transport\Smtp;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\Mailer\Envelope;
|
use Symfony\Component\Mailer\Envelope;
|
||||||
|
use Symfony\Component\Mailer\Exception\TransportException;
|
||||||
use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport;
|
use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport;
|
||||||
use Symfony\Component\Mailer\Transport\Smtp\Stream\AbstractStream;
|
use Symfony\Component\Mailer\Transport\Smtp\Stream\AbstractStream;
|
||||||
use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
|
use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
|
||||||
@ -43,6 +44,29 @@ class SmtpTransportTest extends TestCase
|
|||||||
$this->assertNotContains("NOOP\r\n", $stream->getCommands());
|
$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
|
public function testSendDoesPingAboveThreshold(): void
|
||||||
{
|
{
|
||||||
$stream = new DummyStream();
|
$stream = new DummyStream();
|
||||||
@ -76,13 +100,23 @@ class DummyStream extends AbstractStream
|
|||||||
*/
|
*/
|
||||||
private $commands;
|
private $commands;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $closed = true;
|
||||||
|
|
||||||
public function initialize(): void
|
public function initialize(): void
|
||||||
{
|
{
|
||||||
|
$this->closed = false;
|
||||||
$this->nextResponse = '220 localhost';
|
$this->nextResponse = '220 localhost';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(string $bytes, $debug = true): void
|
public function write(string $bytes, $debug = true): void
|
||||||
{
|
{
|
||||||
|
if ($this->closed) {
|
||||||
|
throw new TransportException('Unable to write bytes on the wire.');
|
||||||
|
}
|
||||||
|
|
||||||
$this->commands[] = $bytes;
|
$this->commands[] = $bytes;
|
||||||
|
|
||||||
if (0 === strpos($bytes, 'DATA')) {
|
if (0 === strpos($bytes, 'DATA')) {
|
||||||
@ -120,4 +154,14 @@ class DummyStream extends AbstractStream
|
|||||||
{
|
{
|
||||||
return 'null';
|
return 'null';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function close(): void
|
||||||
|
{
|
||||||
|
$this->closed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isClosed(): bool
|
||||||
|
{
|
||||||
|
return $this->closed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,12 +206,11 @@ class SmtpTransport extends AbstractTransport
|
|||||||
$this->stream->flush();
|
$this->stream->flush();
|
||||||
$this->executeCommand("\r\n.\r\n", [250]);
|
$this->executeCommand("\r\n.\r\n", [250]);
|
||||||
$message->appendDebug($this->stream->getDebug());
|
$message->appendDebug($this->stream->getDebug());
|
||||||
|
$this->lastMessageTime = microtime(true);
|
||||||
} catch (TransportExceptionInterface $e) {
|
} catch (TransportExceptionInterface $e) {
|
||||||
$e->appendDebug($this->stream->getDebug());
|
$e->appendDebug($this->stream->getDebug());
|
||||||
|
$this->lastMessageTime = 0;
|
||||||
throw $e;
|
throw $e;
|
||||||
} finally {
|
|
||||||
$this->lastMessageTime = microtime(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user