-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: SebastianKrupinski <[email protected]>
- Loading branch information
1 parent
ed78517
commit 83d3a08
Showing
2 changed files
with
171 additions
and
18 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 |
---|---|---|
|
@@ -206,4 +206,140 @@ public function testPerformWithInvalidTo(): void { | |
// test send message | ||
$this->commandSend->perform('user1', '100', $mailMessage); | ||
} | ||
|
||
public function testPerformWithAccountServiceFailure(): void { | ||
// define time factory return | ||
$this->time->method('getTime')->willReturn(1719792000); | ||
// define account service returns | ||
$this->accountService->method('find')->will( | ||
$this->throwException(new \Exception('Something went wrong')) | ||
); | ||
|
||
// construct mail provider message | ||
$mailMessage = $this->mailMessage; | ||
// define exception condition | ||
$this->expectException(SendException::class); | ||
$this->expectExceptionMessage('Error: occurred while retrieving mail account details'); | ||
// test send message | ||
$this->commandSend->perform('user1', '100', $mailMessage); | ||
} | ||
|
||
public function testPerformWithAttachmentServiceFailure(): void { | ||
// define time factory return | ||
$this->time->method('getTime')->willReturn(1719792000); | ||
// define account service returns | ||
$this->accountService->method('find')->will( | ||
$this->returnValueMap([ | ||
['user1', 100, $this->localAccount] | ||
]) | ||
); | ||
// define attachment service returns | ||
$this->attachmentService->expects($this->once())->method('addFileFromString') | ||
->with( | ||
'user1', | ||
$this->mailAttachment->getName(), | ||
$this->mailAttachment->getType(), | ||
$this->mailAttachment->getContents() | ||
)->will( | ||
$this->throwException(new \Exception('Something went wrong')) | ||
); | ||
// construct mail provider message with attachment | ||
$mailMessage = $this->mailMessage; | ||
$mailMessage->setAttachments($this->mailAttachment); | ||
// define exception condition | ||
$this->expectException(SendException::class); | ||
$this->expectExceptionMessage('Error: occurred while saving mail message attachment'); | ||
// test send message | ||
$this->commandSend->perform('user1', '100', $mailMessage); | ||
} | ||
|
||
public function testPerformWithOutboxServiceSaveFailure(): void { | ||
// define time factory return | ||
$this->time->method('getTime')->willReturn(1719792000); | ||
// define account service returns | ||
$this->accountService->method('find')->will( | ||
$this->returnValueMap([ | ||
['user1', 100, $this->localAccount] | ||
]) | ||
); | ||
// construct mail app message objects | ||
$localMessageFresh = $this->localMessageData; | ||
$localMessageFresh['sendAt'] = $this->time->getTime($localMessageFresh); | ||
$localMessageFresh = LocalMessage::fromParams($localMessageFresh); | ||
$localMessageReturned = $this->localMessageData; | ||
$localMessageReturned['id'] = 1; | ||
$localMessageReturned['recipients'] = [['email' => '[email protected]', 'label' => 'User Two']]; | ||
$localMessageReturned['sendAt'] = $this->time->getTime(); | ||
$localMessageReturned = LocalMessage::fromParams($localMessageReturned); | ||
// define attachment service returns | ||
$this->outboxService->expects($this->once())->method('saveMessage') | ||
->with( | ||
$this->localAccount, | ||
$localMessageFresh, | ||
[['email' => '[email protected]', 'label' => 'User Two']], | ||
[], | ||
[], | ||
[] | ||
)->will( | ||
$this->throwException(new \Exception('Something went wrong')) | ||
); | ||
// construct mail provider message | ||
$mailMessage = $this->mailMessage; | ||
// define exception condition | ||
$this->expectException(SendException::class); | ||
$this->expectExceptionMessage('Error: occurred while saving mail message'); | ||
// test send message | ||
$this->commandSend->perform('user1', '100', $mailMessage); | ||
} | ||
|
||
public function testPerformWithOutboxServiceSendFailure(): void { | ||
// define time factory return | ||
$this->time->method('getTime')->willReturn(1719792000); | ||
// define account service returns | ||
$this->accountService->method('find')->will( | ||
$this->returnValueMap([ | ||
['user1', 100, $this->localAccount] | ||
]) | ||
); | ||
// construct mail app message objects | ||
$localMessageFresh = $this->localMessageData; | ||
$localMessageFresh['sendAt'] = $this->time->getTime($localMessageFresh); | ||
$localMessageFresh = LocalMessage::fromParams($localMessageFresh); | ||
$localMessageReturned = $this->localMessageData; | ||
$localMessageReturned['id'] = 1; | ||
$localMessageReturned['recipients'] = [['email' => '[email protected]', 'label' => 'User Two']]; | ||
$localMessageReturned['sendAt'] = $this->time->getTime(); | ||
$localMessageReturned = LocalMessage::fromParams($localMessageReturned); | ||
// define outbox service returns | ||
$this->outboxService->expects($this->once())->method('saveMessage') | ||
->with( | ||
$this->localAccount, | ||
$localMessageFresh, | ||
[['email' => '[email protected]', 'label' => 'User Two']], | ||
[], | ||
[], | ||
[] | ||
)->willReturn($localMessageReturned); | ||
$this->outboxService->expects($this->once())->method('sendMessage') | ||
->with( | ||
$localMessageReturned, | ||
$this->localAccount, | ||
)->will( | ||
$this->throwException(new \Exception('Something went wrong')) | ||
); | ||
// construct mail provider message | ||
$mailMessage = $this->mailMessage; | ||
// define configuration service returns | ||
$this->config->expects($this->once()) | ||
->method('getAppValue') | ||
->with('mail', 'send_system_messages_instantly', 'yes') | ||
->willReturn('yes'); | ||
// construct mail provider message | ||
$mailMessage = $this->mailMessage; | ||
// define exception condition | ||
$this->expectException(SendException::class); | ||
$this->expectExceptionMessage('Error: occurred while sending mail message'); | ||
// test send message | ||
$this->commandSend->perform('user1', '100', $mailMessage); | ||
} | ||
} |