14
14
use Magento \Backend \Model \View \Result \Redirect ;
15
15
use Magento \Backend \Model \View \Result \RedirectFactory ;
16
16
use Magento \Framework \App \RequestInterface ;
17
+ use Magento \Framework \Exception \LocalizedException ;
17
18
use Magento \Framework \Exception \NoSuchEntityException ;
18
19
use Magento \Framework \Message \ManagerInterface ;
19
20
use Magento \Framework \ObjectManagerInterface ;
26
27
use Magento \Sales \Model \Order \Reorder \UnavailableProductsProvider ;
27
28
use PHPUnit \Framework \MockObject \MockObject ;
28
29
use PHPUnit \Framework \TestCase ;
30
+ use Psr \Log \LoggerInterface ;
29
31
30
32
/**
31
33
* Verify reorder class.
@@ -115,6 +117,11 @@ class ReorderTest extends TestCase
115
117
*/
116
118
private $ orderId ;
117
119
120
+ /**
121
+ * @var LoggerInterface|MockObject
122
+ */
123
+ private $ loggerMock ;
124
+
118
125
/**
119
126
* @inheritDoc
120
127
*/
@@ -141,6 +148,7 @@ protected function setUp(): void
141
148
->getMock ();
142
149
$ this ->messageManagerMock = $ this ->getMockBuilder (ManagerInterface::class)
143
150
->getMockForAbstractClass ();
151
+ $ this ->loggerMock = $ this ->getMockForAbstractClass (LoggerInterface::class);
144
152
145
153
$ objectManager = new ObjectManager ($ this );
146
154
$ this ->context = $ objectManager ->getObject (
@@ -161,6 +169,7 @@ protected function setUp(): void
161
169
'reorderHelper ' => $ this ->reorderHelperMock ,
162
170
'context ' => $ this ->context ,
163
171
'resultForwardFactory ' => $ this ->resultForwardFactoryMock ,
172
+ 'logger ' => $ this ->loggerMock
164
173
]
165
174
);
166
175
}
@@ -299,6 +308,43 @@ public function testExecuteRedirectNewOrderWithException(): void
299
308
$ this ->assertInstanceOf (Redirect::class, $ this ->reorder ->execute ());
300
309
}
301
310
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
+
302
348
/**
303
349
* Mock clear storage.
304
350
*
0 commit comments