Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Use transport factory in Writer\Mail constructor #2

Merged
merged 3 commits into from
Jun 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Writer/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions test/Writer/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}