Skip to content
Snippets Groups Projects
Commit baa78459 authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Add mechanism to reset an SMTP connection. (#1475)

- Potentially useful for retrying after encountering problems.
parent 4cd194b0
No related merge requests found
...@@ -104,6 +104,21 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface ...@@ -104,6 +104,21 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface
return $message; return $message;
} }
/**
* Reset the connection in the transport. Implements a fluent interface.
*
* @return Mailer
*/
public function resetConnection()
{
// If the transport has a disconnect method, call it:
$transport = $this->getTransport();
if (is_callable([$transport, 'disconnect'])) {
$transport->disconnect();
}
return $this;
}
/** /**
* Set the mail transport object. * Set the mail transport object.
* *
......
...@@ -374,6 +374,19 @@ class MailerTest extends \VuFindTest\Unit\TestCase ...@@ -374,6 +374,19 @@ class MailerTest extends \VuFindTest\Unit\TestCase
$mailer = new Mailer($transport); $mailer = new Mailer($transport);
$mailer->sendRecord('to@example.com', 'from@example.com', 'message', $driver, $view); $mailer->sendRecord('to@example.com', 'from@example.com', 'message', $driver, $view);
} }
/**
* Test connection reset
*
* @return void
*/
public function testResetConnection()
{
$transport = $this->createMock(\Zend\Mail\Transport\Smtp::class);
$transport->expects($this->once())->method('disconnect');
$mailer = new Mailer($transport);
$mailer->resetConnection();
}
} }
class MockEmailRenderer extends \Zend\View\Renderer\PhpRenderer class MockEmailRenderer extends \Zend\View\Renderer\PhpRenderer
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment