diff --git a/src/Queue/QueueProcessor.php b/src/Queue/QueueProcessor.php index df1b02d3..48adca4a 100644 --- a/src/Queue/QueueProcessor.php +++ b/src/Queue/QueueProcessor.php @@ -3,6 +3,7 @@ namespace Genkgo\Mail\Queue; +use Genkgo\Mail\Exception\AbstractProtocolException; use Genkgo\Mail\Exception\ConnectionRefusedException; use Genkgo\Mail\Exception\EmptyQueueException; use Genkgo\Mail\TransportInterface; @@ -43,7 +44,7 @@ public function process() while ($message = $queue->fetch()) { try { $this->transport->send($message); - } catch (ConnectionRefusedException $e) { + } catch (AbstractProtocolException $e) { $queue->store($message); // do not continue transporting messages diff --git a/test/Unit/Queue/ProcessorTest.php b/test/Unit/Queue/ProcessorTest.php index b215bfb0..e9b7081a 100644 --- a/test/Unit/Queue/ProcessorTest.php +++ b/test/Unit/Queue/ProcessorTest.php @@ -2,6 +2,7 @@ namespace Genkgo\TestMail\Unit\Queue; +use Genkgo\Mail\Exception\AbstractProtocolException; use Genkgo\TestMail\AbstractTestCase;; use Genkgo\Mail\Exception\ConnectionRefusedException; use Genkgo\Mail\GenericMessage; @@ -81,6 +82,34 @@ public function it_will_readd_failed_messages_to_queue() { $this->assertCount(3, $storage); } + /** + * @test + */ + public function it_will_readd_messages_resulting_in_any_protocol_exception() { + $storage = new \ArrayObject(); + + $queue = new ArrayObjectQueue($storage); + $queue->store($this->newMessage('Test 1')); + $queue->store($this->newMessage('Test 2')); + $queue->store($this->newMessage('Test 3')); + + $transport = $this->createMock(TransportInterface::class); + $transport + ->expects($this->once()) + ->method('send') + ->with($this->callback(function (GenericMessage $message) { + $this->assertEquals('Test 1', $message->getHeader('subject')[0]->getValue()); + return true; + })) + ->willThrowException(new class extends AbstractProtocolException{}) + ; + + $processor = new QueueProcessor($transport, [$queue]); + $processor->process(); + + $this->assertCount(3, $storage); + } + /** * @param string $subject * @return MessageInterface