Skip to content

Commit 13e94a0

Browse files
committed
MC-39796: Exception when trying to reorder out of stock product
- Removing exception from the exception log
1 parent 285b397 commit 13e94a0

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Reorder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ public function execute()
119119
$this->_getOrderCreateModel()->initFromOrder($order);
120120
$resultRedirect->setPath('sales/*');
121121
} catch (\Magento\Framework\Exception\LocalizedException $e) {
122-
$this->logger->critical($e);
123122
$this->messageManager->addErrorMessage($e->getMessage());
124123
return $resultRedirect->setPath('sales/*');
125124
} catch (\Exception $e) {

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Create/ReorderTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Backend\Model\View\Result\Redirect;
1515
use Magento\Backend\Model\View\Result\RedirectFactory;
1616
use Magento\Framework\App\RequestInterface;
17+
use Magento\Framework\Exception\LocalizedException;
1718
use Magento\Framework\Exception\NoSuchEntityException;
1819
use Magento\Framework\Message\ManagerInterface;
1920
use Magento\Framework\ObjectManagerInterface;
@@ -26,6 +27,7 @@
2627
use Magento\Sales\Model\Order\Reorder\UnavailableProductsProvider;
2728
use PHPUnit\Framework\MockObject\MockObject;
2829
use PHPUnit\Framework\TestCase;
30+
use Psr\Log\LoggerInterface;
2931

3032
/**
3133
* Verify reorder class.
@@ -115,6 +117,11 @@ class ReorderTest extends TestCase
115117
*/
116118
private $orderId;
117119

120+
/**
121+
* @var LoggerInterface|MockObject
122+
*/
123+
private $loggerMock;
124+
118125
/**
119126
* @inheritDoc
120127
*/
@@ -141,6 +148,7 @@ protected function setUp(): void
141148
->getMock();
142149
$this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class)
143150
->getMockForAbstractClass();
151+
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
144152

145153
$objectManager = new ObjectManager($this);
146154
$this->context = $objectManager->getObject(
@@ -161,6 +169,7 @@ protected function setUp(): void
161169
'reorderHelper' => $this->reorderHelperMock,
162170
'context' => $this->context,
163171
'resultForwardFactory' => $this->resultForwardFactoryMock,
172+
'logger' => $this->loggerMock
164173
]
165174
);
166175
}
@@ -299,6 +308,43 @@ public function testExecuteRedirectNewOrderWithException(): void
299308
$this->assertInstanceOf(Redirect::class, $this->reorder->execute());
300309
}
301310

311+
/**
312+
* Verify redirect new order with throws out of stock exception.
313+
*
314+
* @return void
315+
*/
316+
public function testExecuteReorderWithThrowsLocalizedException(): void
317+
{
318+
$errorPhrase = __('This product is out of stock.');
319+
$exception = new LocalizedException($errorPhrase);
320+
321+
$this->clearStorage();
322+
$this->getOrder();
323+
$this->canReorder(true);
324+
$this->createRedirect();
325+
$this->getOrderId($this->orderId);
326+
$this->getUnavailableProducts([]);
327+
328+
$this->orderMock->expects($this->once())
329+
->method('setReordered')
330+
->with(true)
331+
->willThrowException($exception);
332+
$this->loggerMock
333+
->expects($this->any())
334+
->method('critical')
335+
->willReturn($exception);
336+
$this->messageManagerMock
337+
->expects($this->once())
338+
->method('addErrorMessage')
339+
->willReturnSelf();
340+
$this->resultRedirectMock
341+
->expects($this->once())
342+
->method('setPath')
343+
->with('sales/*')
344+
->willReturnSelf();
345+
$this->assertInstanceOf(Redirect::class, $this->reorder->execute());
346+
}
347+
302348
/**
303349
* Mock clear storage.
304350
*

0 commit comments

Comments
 (0)