-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from visto9259/master
To fix issue #3
- Loading branch information
Showing
3 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace LmcMailTest\Mock; | ||
|
||
class MockAddress implements \Laminas\Mail\Address\AddressInterface | ||
{ | ||
|
||
const EMAIL_ADDRESS = '[email protected]'; | ||
const NAME = 'Test Example'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getEmail() | ||
{ | ||
return self::EMAIL_ADDRESS; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getName() | ||
{ | ||
return self::NAME; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function toString() | ||
{ | ||
return sprintf('%s <%s>', self::NAME, self::EMAIL_ADDRESS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,14 @@ | |
|
||
namespace Service; | ||
|
||
use Laminas\Mail\AddressList; | ||
use Laminas\Mail\Message; | ||
use Laminas\Mime\Message as MimeMessage; | ||
use Laminas\ServiceManager\ServiceManager; | ||
use Laminas\View\Model\ViewModel; | ||
use LmcMail\Service\MessageService; | ||
use LmcMailTest\Util\ServiceManagerFactory; | ||
use LmcMailTest\Mock\MockAddress; | ||
|
||
class MessageServiceTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
@@ -81,7 +83,36 @@ public function testCreateHtmlMessageManyTos() | |
$this->assertCount(2, $to); | ||
$addresses = $to->get('[email protected]'); | ||
$this->assertNotFalse($addresses,'Address not found'); | ||
$this->assertEquals('[email protected]', $addresses->getEmail(), "Was expecting email address to be [email protected]"); | ||
$this->assertEquals('[email protected]', $addresses->getEmail(), "Was expecting email address to be [email protected]"); | ||
} | ||
|
||
public function testCreateHtmlMessageAddressListTo() | ||
{ | ||
$addressList = new AddressList(); | ||
$addressList->add('[email protected]'); | ||
$addressList->add('[email protected]'); | ||
$message = $this->messageService->createHtmlMessage([],$addressList, 'test','mail/test_html'); | ||
$this->assertInstanceOf(Message::class, $message); | ||
$body = $message->getBody(); | ||
$this->assertInstanceOf(MimeMessage::class, $body); | ||
$to = $message->getTo(); | ||
$this->assertCount(2, $to); | ||
$addresses = $to->get('[email protected]'); | ||
$this->assertNotFalse($addresses,'Address not found'); | ||
$this->assertEquals('[email protected]', $addresses->getEmail(), "Was expecting email address to be [email protected]"); | ||
} | ||
|
||
public function testCreateHtmlMessageAddressInterfaceTo() | ||
{ | ||
$message = $this->messageService->createHtmlMessage([],new MockAddress(), 'test','mail/test_html'); | ||
$this->assertInstanceOf(Message::class, $message); | ||
$body = $message->getBody(); | ||
$this->assertInstanceOf(MimeMessage::class, $body); | ||
$to = $message->getTo(); | ||
$this->assertCount(1, $to); | ||
$addresses = $to->get('[email protected]'); | ||
$this->assertNotFalse($addresses,'Address not found'); | ||
$this->assertEquals('[email protected]', $addresses->getEmail(), "Was expecting email address to be [email protected]"); | ||
} | ||
|
||
public function testSendTextMessage() | ||
|