Skip to content

Commit add1e14

Browse files
pawciomamageprince
authored andcommitted
Issues 13769. Fix wrong info about sent email in order sender.
1 parent b42f13b commit add1e14

File tree

2 files changed

+49
-19
lines changed

2 files changed

+49
-19
lines changed

app/code/Magento/Sales/Model/Order/Email/Sender.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ protected function checkAndSend(Order $order)
7878
$sender->sendCopyTo();
7979
} catch (\Exception $e) {
8080
$this->logger->error($e->getMessage());
81+
82+
return false;
8183
}
8284

8385
return true;

app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/OrderSenderTest.php

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ protected function setUp()
5959
* @param int $configValue
6060
* @param bool|null $forceSyncMode
6161
* @param bool|null $emailSendingResult
62-
* @dataProvider sendDataProvider
62+
* @param $senderSendException
6363
* @return void
64+
* @dataProvider sendDataProvider
6465
*/
65-
public function testSend($configValue, $forceSyncMode, $emailSendingResult)
66+
public function testSend($configValue, $forceSyncMode, $emailSendingResult, $senderSendException)
6667
{
6768
$address = 'address_test';
6869
$configPath = 'sales_email/general/async_sending';
@@ -122,19 +123,23 @@ public function testSend($configValue, $forceSyncMode, $emailSendingResult)
122123

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

125-
$this->senderMock->expects($this->once())->method('sendCopyTo');
126+
if ($senderSendException) {
127+
$this->checkSenderSendExceptionCase();
128+
} else {
129+
$this->senderMock->expects($this->once())->method('sendCopyTo');
126130

127-
$this->orderMock->expects($this->once())
128-
->method('setEmailSent')
129-
->with(true);
131+
$this->orderMock->expects($this->once())
132+
->method('setEmailSent')
133+
->with(true);
130134

131-
$this->orderResourceMock->expects($this->once())
132-
->method('saveAttribute')
133-
->with($this->orderMock, ['send_email', 'email_sent']);
135+
$this->orderResourceMock->expects($this->once())
136+
->method('saveAttribute')
137+
->with($this->orderMock, ['send_email', 'email_sent']);
134138

135-
$this->assertTrue(
136-
$this->sender->send($this->orderMock)
137-
);
139+
$this->assertTrue(
140+
$this->sender->send($this->orderMock)
141+
);
142+
}
138143
} else {
139144
$this->orderResourceMock->expects($this->once())
140145
->method('saveAttribute')
@@ -155,19 +160,42 @@ public function testSend($configValue, $forceSyncMode, $emailSendingResult)
155160
}
156161
}
157162

163+
/**
164+
* Methods check case when method "send" in "senderMock" throw exception.
165+
*
166+
* @return void
167+
*/
168+
protected function checkSenderSendExceptionCase()
169+
{
170+
$this->senderMock->expects($this->once())
171+
->method('send')
172+
->willThrowException(new \Exception('exception'));
173+
174+
$this->orderResourceMock->expects($this->once())
175+
->method('saveAttribute')
176+
->with($this->orderMock, 'send_email');
177+
178+
$this->assertFalse(
179+
$this->sender->send($this->orderMock)
180+
);
181+
}
182+
158183
/**
159184
* @return array
160185
*/
161186
public function sendDataProvider()
162187
{
163188
return [
164-
[0, 0, true],
165-
[0, 0, true],
166-
[0, 0, false],
167-
[0, 0, false],
168-
[0, 1, true],
169-
[0, 1, true],
170-
[1, null, null, null]
189+
[0, 0, true, false],
190+
[0, 0, true, false],
191+
[0, 0, true, true],
192+
[0, 0, false, false],
193+
[0, 0, false, false],
194+
[0, 0, false, true],
195+
[0, 1, true, false],
196+
[0, 1, true, false],
197+
[0, 1, true, false],
198+
[1, null, null, false]
171199
];
172200
}
173201

0 commit comments

Comments
 (0)