28
28
use Magento \Framework \Lock \LockManagerInterface ;
29
29
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
30
30
use Magento \Quote \Api \CartRepositoryInterface ;
31
+ use Magento \Quote \Model \CartMutexInterface ;
31
32
use Magento \Quote \Model \CustomerManagement ;
32
33
use Magento \Quote \Model \Quote ;
33
34
use Magento \Quote \Model \Quote \Address ;
@@ -203,8 +204,12 @@ class QuoteManagementTest extends TestCase
203
204
private $ lockManagerMock ;
204
205
205
206
/**
206
- * @inheritDoc
207
- *
207
+ * @var CartMutexInterface
208
+ */
209
+ private $ cartMutexMock ;
210
+
211
+ /**
212
+ * @inheriDoc
208
213
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
209
214
*/
210
215
protected function setUp (): void
@@ -255,6 +260,12 @@ protected function setUp(): void
255
260
'setCustomerId ' ,
256
261
'setRemoteIp ' ,
257
262
'setXForwardedFor ' ,
263
+ 'getCustomerFirstname ' ,
264
+ 'getCustomerLastname ' ,
265
+ 'getCustomerMiddlename ' ,
266
+ 'setCustomerFirstname ' ,
267
+ 'setCustomerLastname ' ,
268
+ 'setCustomerMiddlename '
258
269
]
259
270
)
260
271
->onlyMethods (
@@ -301,6 +312,9 @@ protected function setUp(): void
301
312
$ this ->lockManagerMock = $ this ->getMockBuilder (LockManagerInterface::class)
302
313
->getMockForAbstractClass ();
303
314
315
+ $ this ->cartMutexMock = $ this ->getMockBuilder (CartMutexInterface::class)
316
+ ->getMockForAbstractClass ();
317
+
304
318
$ this ->model = $ objectManager ->getObject (
305
319
QuoteManagement::class,
306
320
[
@@ -838,6 +852,7 @@ public function testSubmit(): void
838
852
/**
839
853
* @dataProvider guestPlaceOrderDataProvider
840
854
* @return void
855
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
841
856
*/
842
857
public function testPlaceOrderIfCustomerIsGuest (?string $ settledEmail , int $ countSetAddress ): void
843
858
{
@@ -846,6 +861,9 @@ public function testPlaceOrderIfCustomerIsGuest(?string $settledEmail, int $coun
846
861
$ orderIncrementId = 100003332 ;
847
862
$ orderStatus = 'status1 ' ;
848
863
$ email = 'email@mail.com ' ;
864
+ $ firstName = 'TestFirst ' ;
865
+ $ middleName = 'TestMiddle ' ;
866
+ $ lastName = 'TestLast ' ;
849
867
850
868
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
851
869
->method ('getActive ' )
@@ -870,12 +888,44 @@ public function testPlaceOrderIfCustomerIsGuest(?string $settledEmail, int $coun
870
888
->with ($ email )
871
889
->willReturnSelf ();
872
890
873
- $ addressMock = $ this ->createPartialMock (Address::class, ['getEmail ' ]);
891
+ $ addressMock = $ this ->createPartialMock (
892
+ Address::class,
893
+ [
894
+ 'getEmail ' ,
895
+ 'getFirstname ' ,
896
+ 'getLastname ' ,
897
+ 'getMiddlename '
898
+ ]
899
+ );
874
900
$ addressMock ->expects ($ this ->exactly ($ countSetAddress ))->method ('getEmail ' )->willReturn ($ email );
875
901
$ this ->quoteMock ->expects ($ this ->any ())->method ('getBillingAddress ' )->with ()->willReturn ($ addressMock );
876
902
877
903
$ this ->quoteMock ->expects ($ this ->once ())->method ('setCustomerIsGuest ' )->with (true )->willReturnSelf ();
878
904
$ this ->quoteMock ->expects ($ this ->once ())->method ('getCustomerId ' )->willReturn (null );
905
+ $ this ->quoteMock ->expects ($ this ->once ())
906
+ ->method ('getCustomerFirstname ' )
907
+ ->willReturn (null );
908
+ $ this ->quoteMock ->expects ($ this ->once ())
909
+ ->method ('getCustomerLastname ' )
910
+ ->willReturn (null );
911
+ $ addressMock ->expects ($ this ->once ())
912
+ ->method ('getFirstname ' )
913
+ ->willReturn ($ firstName );
914
+ $ addressMock ->expects ($ this ->once ())
915
+ ->method ('getLastname ' )
916
+ ->willReturn ($ lastName );
917
+ $ this ->quoteMock ->expects ($ this ->once ())
918
+ ->method ('setCustomerFirstname ' )
919
+ ->willReturn ($ firstName );
920
+ $ this ->quoteMock ->expects ($ this ->once ())
921
+ ->method ('setCustomerLastname ' )
922
+ ->willReturn ($ lastName );
923
+ $ addressMock ->expects ($ this ->exactly (2 ))
924
+ ->method ('getMiddlename ' )
925
+ ->willReturn ($ middleName );
926
+ $ this ->quoteMock ->expects ($ this ->once ())
927
+ ->method ('setCustomerLastname ' )
928
+ ->willReturn ($ middleName );
879
929
$ this ->quoteMock ->expects ($ this ->once ())
880
930
->method ('setCustomerGroupId ' )
881
931
->with (GroupInterface::NOT_LOGGED_IN_ID );
@@ -908,7 +958,8 @@ public function testPlaceOrderIfCustomerIsGuest(?string $settledEmail, int $coun
908
958
'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock ,
909
959
'addressRepository ' => $ this ->addressRepositoryMock ,
910
960
'request ' => $ this ->requestMock ,
911
- 'remoteAddress ' => $ this ->remoteAddressMock
961
+ 'remoteAddress ' => $ this ->remoteAddressMock ,
962
+ 'cartMutex ' => $ this ->cartMutexMock
912
963
]
913
964
)
914
965
->getMock ();
@@ -990,7 +1041,8 @@ public function testPlaceOrder(): void
990
1041
'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock ,
991
1042
'addressRepository ' => $ this ->addressRepositoryMock ,
992
1043
'request ' => $ this ->requestMock ,
993
- 'remoteAddress ' => $ this ->remoteAddressMock
1044
+ 'remoteAddress ' => $ this ->remoteAddressMock ,
1045
+ 'cartMutex ' => $ this ->cartMutexMock
994
1046
]
995
1047
)
996
1048
->getMock ();
0 commit comments