diff --git a/app/code/Magento/Sales/Model/Order/Email/Sender.php b/app/code/Magento/Sales/Model/Order/Email/Sender.php index 8ada6a3f321d2..6d4480c4c45e0 100644 --- a/app/code/Magento/Sales/Model/Order/Email/Sender.php +++ b/app/code/Magento/Sales/Model/Order/Email/Sender.php @@ -84,6 +84,8 @@ protected function checkAndSend(Order $order) $sender->sendCopyTo(); } catch (\Exception $e) { $this->logger->error($e->getMessage()); + + return false; } return true; diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/OrderSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/OrderSenderTest.php index 411dd9e1433d7..46c44c03b1514 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/OrderSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/OrderSenderTest.php @@ -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'; @@ -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') @@ -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] ]; }