Skip to content
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
2 changes: 2 additions & 0 deletions app/code/Magento/Sales/Model/Order/Email/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ protected function checkAndSend(Order $order)
$sender->sendCopyTo();
} catch (\Exception $e) {
$this->logger->error($e->getMessage());

return false;
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ protected function setUp()
* @param int $configValue
* @param bool|null $forceSyncMode
* @param bool|null $emailSendingResult
* @dataProvider sendDataProvider
* @param $senderSendException
* @return void
* @dataProvider sendDataProvider
*/
public function testSend($configValue, $forceSyncMode, $emailSendingResult)
public function testSend($configValue, $forceSyncMode, $emailSendingResult, $senderSendException)
{
$address = 'address_test';
$configPath = 'sales_email/general/async_sending';
Expand Down Expand Up @@ -110,19 +111,23 @@ public function testSend($configValue, $forceSyncMode, $emailSendingResult)

$this->senderMock->expects($this->once())->method('send');

$this->senderMock->expects($this->once())->method('sendCopyTo');
if ($senderSendException) {
$this->checkSenderSendExceptionCase();
} else {
$this->senderMock->expects($this->once())->method('sendCopyTo');

$this->orderMock->expects($this->once())
->method('setEmailSent')
->with(true);
$this->orderMock->expects($this->once())
->method('setEmailSent')
->with(true);

$this->orderResourceMock->expects($this->once())
->method('saveAttribute')
->with($this->orderMock, ['send_email', 'email_sent']);
$this->orderResourceMock->expects($this->once())
->method('saveAttribute')
->with($this->orderMock, ['send_email', 'email_sent']);

$this->assertTrue(
$this->sender->send($this->orderMock)
);
$this->assertTrue(
$this->sender->send($this->orderMock)
);
}
} else {
$this->orderResourceMock->expects($this->once())
->method('saveAttribute')
Expand All @@ -146,19 +151,42 @@ public function testSend($configValue, $forceSyncMode, $emailSendingResult)
}
}

/**
* Methods check case when method "send" in "senderMock" throw exception.
*
* @return void
*/
protected function checkSenderSendExceptionCase()
{
$this->senderMock->expects($this->once())
->method('send')
->willThrowException(new \Exception('exception'));

$this->orderResourceMock->expects($this->once())
->method('saveAttribute')
->with($this->orderMock, 'send_email');

$this->assertFalse(
$this->sender->send($this->orderMock)
);
}

/**
* @return array
*/
public function sendDataProvider()
{
return [
[0, 0, true],
[0, 0, true],
[0, 0, false],
[0, 0, false],
[0, 1, true],
[0, 1, true],
[1, null, null, null]
[0, 0, true, false],
[0, 0, true, false],
[0, 0, true, true],
[0, 0, false, false],
[0, 0, false, false],
[0, 0, false, true],
[0, 1, true, false],
[0, 1, true, false],
[0, 1, true, false],
[1, null, null, false]
];
}

Expand Down