diff --git a/src/Writer/Mail.php b/src/Writer/Mail.php index fd0ca9d1..41f79f7f 100644 --- a/src/Writer/Mail.php +++ b/src/Writer/Mail.php @@ -90,6 +90,9 @@ public function __construct($mail, Transport\TransportInterface $transport = nul if (is_array($mail)) { $mail = MailMessageFactory::getInstance($mail); } + if (is_array($transport)) { + $transport = Transport\Factory::create($transport); + } } // Ensure we have a valid mail message diff --git a/test/Writer/MailTest.php b/test/Writer/MailTest.php index e261b29b..91eac599 100644 --- a/test/Writer/MailTest.php +++ b/test/Writer/MailTest.php @@ -128,4 +128,35 @@ public function testConstructWithMailAsArrayOptions() $this->assertAttributeInstanceOf('Zend\Mail\Message', 'mail', $writer); } + + public function testConstructWithMailTransportAsArrayOptions() + { + $messageOptions = [ + 'encoding' => 'UTF-8', + 'from' => 'matthew@example.com', + 'to' => 'zf-devteam@example.com', + 'subject' => 'subject', + 'body' => 'body', + ]; + + $transportOptions = [ + 'type' => 'smtp', + 'options' => [ + 'host' => 'test.dev', + 'connection_class' => 'login', + 'connection_config' => [ + 'username' => 'foo', + 'smtp_password' => 'bar', + 'ssl' => 'tls' + ] + ] + ]; + + $writer = new MailWriter([ + 'mail' => $messageOptions, + 'transport' => $transportOptions, + ]); + + $this->assertAttributeInstanceOf('Zend\Mail\Transport\Smtp', 'transport', $writer); + } }