check failed recipients, fixes #8
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
d10183c76c
commit
373974a40d
|
@ -117,9 +117,12 @@ class Request {
|
||||||
$message->setFrom([$senderAddress => $senderName]);
|
$message->setFrom([$senderAddress => $senderName]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->mailer->send($message);
|
$failedRecipients = $this->mailer->send($message);
|
||||||
|
if(count($failedRecipients) > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $e;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -212,7 +212,27 @@ class RequestTest extends \Test\TestCase {
|
||||||
$this->assertSame($adminsWithEmail, count($result));
|
$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';
|
$adminName = 'Elu Thingol';
|
||||||
$adminMail = 'elu-thingol@sindar.gov';
|
$adminMail = 'elu-thingol@sindar.gov';
|
||||||
$admin = $this->createMock(IUser::class);
|
$admin = $this->createMock(IUser::class);
|
||||||
|
@ -247,15 +267,21 @@ class RequestTest extends \Test\TestCase {
|
||||||
$this->mailer->expects($this->once())
|
$this->mailer->expects($this->once())
|
||||||
->method('createMessage')
|
->method('createMessage')
|
||||||
->willReturn($message);
|
->willReturn($message);
|
||||||
$this->mailer->expects($this->once())
|
|
||||||
|
$sendMocker = $this->mailer->expects($this->once())
|
||||||
->method('send')
|
->method('send')
|
||||||
->with($message);
|
->with($message);
|
||||||
|
if($sendThrowsException) {
|
||||||
|
$sendMocker->willThrowException(new \Exception('Expected Exception'));
|
||||||
|
} else {
|
||||||
|
$sendMocker->willReturn($sendResult);
|
||||||
|
}
|
||||||
|
|
||||||
$this->defaults->expects($this->atLeastOnce())
|
$this->defaults->expects($this->atLeastOnce())
|
||||||
->method('getName')
|
->method('getName')
|
||||||
->willReturn('Cloud of Sindar');
|
->willReturn('Cloud of Sindar');
|
||||||
|
|
||||||
$result = $this->invokePrivate($this->service, 'craftEmailTo', [$admin, $template]);
|
$result = $this->invokePrivate($this->service, 'craftEmailTo', [$admin, $template]);
|
||||||
$this->assertTrue($result);
|
$this->assertSame($expectedResult, $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue