Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To fix issue #3 #4

Merged
merged 1 commit into from
Apr 5, 2023
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
8 changes: 4 additions & 4 deletions src/Service/MessageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function createHtmlMessage(string|Address|AddressInterface|array|AddressL

/**
* Create a text message
* @param string|Address|AddressInterface|array|AddressList|Traversable $from
* @param string|Address|AddressInterface|array|AddressList|Traversable|null $from
* @param string|Address|AddressInterface|array|AddressList|Traversable $to
* @param string $subject
* @param string|ModelInterface $nameOrModel
Expand Down Expand Up @@ -180,16 +180,16 @@ public function send(Message $message): void

/**
* Create default message
* @param string|Address|AddressInterface|array|AddressList|Traversable $from
* @param string|Address|AddressInterface|array|AddressList|Traversable|null $from
* @param string $encoding
* @param string|array $to
* @param string|Address|AddressInterface|array|AddressList|Traversable $to
* @param string $subject
* @param MimeMessage|string $body
* @return Message
*/
protected function getDefaultMessage(string|Address|AddressInterface|array|AddressList|Traversable|null $from,
string $encoding,
string|array $to,
string|Address|AddressInterface|array|AddressList|Traversable $to,
string $subject,
MimeMessage|string $body): Message
{
Expand Down
34 changes: 34 additions & 0 deletions test/LmcMailTest/Mock/MockAddress.php
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);
}
}
33 changes: 32 additions & 1 deletion test/LmcMailTest/Service/MessageServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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()
Expand Down