check failed recipients, fixes #8

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2018-06-14 14:41:42 +02:00
parent d10183c76c
commit 373974a40d
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
2 changed files with 34 additions and 5 deletions

View File

@ -117,9 +117,12 @@ class Request {
$message->setFrom([$senderAddress => $senderName]);
try {
$this->mailer->send($message);
$failedRecipients = $this->mailer->send($message);
if(count($failedRecipients) > 0) {
return false;
}
} catch (\Exception $e) {
return $e;
return false;
}
return true;

View File

@ -212,7 +212,27 @@ class RequestTest extends \Test\TestCase {
$this->assertSame($adminsWithEmail, count($result));
}
public function testSendMail() {
public function mailerSendProvider() {
return [
[
false, [], true
],
[
false, ['elu-thingol@sindar.gov'], false
],
[
true, [], false
]
];
}
/**
* @dataProvider mailerSendProvider
* @param $sendThrowsException
* @param $sendResult
* @param $expectedResult
*/
public function testSendMail($sendThrowsException, $sendResult, $expectedResult) {
$adminName = 'Elu Thingol';
$adminMail = 'elu-thingol@sindar.gov';
$admin = $this->createMock(IUser::class);
@ -247,15 +267,21 @@ class RequestTest extends \Test\TestCase {
$this->mailer->expects($this->once())
->method('createMessage')
->willReturn($message);
$this->mailer->expects($this->once())
$sendMocker = $this->mailer->expects($this->once())
->method('send')
->with($message);
if($sendThrowsException) {
$sendMocker->willThrowException(new \Exception('Expected Exception'));
} else {
$sendMocker->willReturn($sendResult);
}
$this->defaults->expects($this->atLeastOnce())
->method('getName')
->willReturn('Cloud of Sindar');
$result = $this->invokePrivate($this->service, 'craftEmailTo', [$admin, $template]);
$this->assertTrue($result);
$this->assertSame($expectedResult, $result);
}
}