1414use Magento \Backend \Model \View \Result \Redirect ;
1515use Magento \Backend \Model \View \Result \RedirectFactory ;
1616use Magento \Framework \App \RequestInterface ;
17+ use Magento \Framework \Exception \LocalizedException ;
1718use Magento \Framework \Exception \NoSuchEntityException ;
1819use Magento \Framework \Message \ManagerInterface ;
1920use Magento \Framework \ObjectManagerInterface ;
2627use Magento \Sales \Model \Order \Reorder \UnavailableProductsProvider ;
2728use PHPUnit \Framework \MockObject \MockObject ;
2829use 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