9
9
10
10
use Magento \Framework \App \ResourceConnection ;
11
11
use Magento \Framework \DB \Adapter \AdapterInterface ;
12
+ use Magento \Framework \DB \Select ;
12
13
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
13
14
use Magento \Sales \Api \Data \OrderInterface ;
14
15
use Magento \Sales \Api \Data \ShipmentCommentCreationInterface ;
27
28
use Magento \Sales \Model \Order \Shipment \OrderRegistrarInterface ;
28
29
use Magento \Sales \Model \Order \ShipmentDocumentFactory ;
29
30
use Magento \Sales \Model \Order \Validation \ShipOrderInterface ;
31
+ use Magento \Sales \Model \OrderMutex ;
30
32
use Magento \Sales \Model \ShipOrder ;
31
33
use Magento \Sales \Model \ValidatorResultInterface ;
32
34
use PHPUnit \Framework \MockObject \MockObject ;
@@ -208,7 +210,8 @@ protected function setUp(): void
208
210
'shipOrderValidator ' => $ this ->shipOrderValidatorMock ,
209
211
'notifierInterface ' => $ this ->notifierInterfaceMock ,
210
212
'logger ' => $ this ->loggerMock ,
211
- 'orderRegistrar ' => $ this ->orderRegistrarMock
213
+ 'orderRegistrar ' => $ this ->orderRegistrarMock ,
214
+ 'orderMutex ' => new OrderMutex ($ this ->resourceConnectionMock )
212
215
]
213
216
);
214
217
}
@@ -224,10 +227,7 @@ protected function setUp(): void
224
227
*/
225
228
public function testExecute ($ orderId , $ items , $ notify , $ appendComment )
226
229
{
227
- $ this ->resourceConnectionMock ->expects ($ this ->once ())
228
- ->method ('getConnection ' )
229
- ->with ('sales ' )
230
- ->willReturn ($ this ->adapterMock );
230
+ $ this ->mockConnection ($ orderId );
231
231
$ this ->orderRepositoryMock ->expects ($ this ->once ())
232
232
->method ('get ' )
233
233
->willReturn ($ this ->orderMock );
@@ -320,7 +320,7 @@ public function testDocumentValidationException()
320
320
$ notify = true ;
321
321
$ appendComment = true ;
322
322
$ errorMessages = ['error1 ' , 'error2 ' ];
323
-
323
+ $ this -> mockConnection ( $ orderId );
324
324
$ this ->orderRepositoryMock ->expects ($ this ->once ())
325
325
->method ('get ' )
326
326
->willReturn ($ this ->orderMock );
@@ -375,10 +375,7 @@ public function testCouldNotShipException()
375
375
$ items = [1 => 2 ];
376
376
$ notify = true ;
377
377
$ appendComment = true ;
378
- $ this ->resourceConnectionMock ->expects ($ this ->once ())
379
- ->method ('getConnection ' )
380
- ->with ('sales ' )
381
- ->willReturn ($ this ->adapterMock );
378
+ $ this ->mockConnection ($ orderId );
382
379
383
380
$ this ->orderRepositoryMock ->expects ($ this ->once ())
384
381
->method ('get ' )
@@ -447,4 +444,34 @@ public function dataProvider()
447
444
'TestWithNotifyFalse ' => [1 , [1 => 2 ], false , true ],
448
445
];
449
446
}
447
+
448
+ /**
449
+ * @param int $orderId
450
+ */
451
+ private function mockConnection (int $ orderId ): void
452
+ {
453
+ $ select = $ this ->createMock (Select::class);
454
+ $ select ->expects ($ this ->once ())
455
+ ->method ('from ' )
456
+ ->with ('sales_order ' , 'entity_id ' )
457
+ ->willReturnSelf ();
458
+ $ select ->expects ($ this ->once ())
459
+ ->method ('where ' )
460
+ ->with ('entity_id = ? ' , $ orderId )
461
+ ->willReturnSelf ();
462
+ $ select ->expects ($ this ->once ())
463
+ ->method ('forUpdate ' )
464
+ ->with (true )
465
+ ->willReturnSelf ();
466
+ $ this ->adapterMock ->expects ($ this ->once ())
467
+ ->method ('select ' )
468
+ ->willReturn ($ select );
469
+ $ this ->resourceConnectionMock ->expects ($ this ->once ())
470
+ ->method ('getConnection ' )
471
+ ->with ('sales ' )
472
+ ->willReturn ($ this ->adapterMock );
473
+ $ this ->resourceConnectionMock ->expects ($ this ->once ())
474
+ ->method ('getTableName ' )
475
+ ->willReturnArgument (0 );
476
+ }
450
477
}
0 commit comments