Skip to content

Commit 236402e

Browse files
committed
39067: cover unit test
1 parent 50075cd commit 236402e

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -28,6 +28,7 @@
2828
use Magento\Framework\Lock\LockManagerInterface;
2929
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
3030
use Magento\Quote\Api\CartRepositoryInterface;
31+
use Magento\Quote\Model\CartMutexInterface;
3132
use Magento\Quote\Model\CustomerManagement;
3233
use Magento\Quote\Model\Quote;
3334
use Magento\Quote\Model\Quote\Address;
@@ -202,6 +203,11 @@ class QuoteManagementTest extends TestCase
202203
*/
203204
private $lockManagerMock;
204205

206+
/**
207+
* @var CartMutexInterface
208+
*/
209+
private $cartMutexMock;
210+
205211
/**
206212
* @inheriDoc
207213
*
@@ -255,6 +261,12 @@ protected function setUp(): void
255261
'setCustomerId',
256262
'setRemoteIp',
257263
'setXForwardedFor',
264+
'getCustomerFirstname',
265+
'getCustomerLastname',
266+
'getCustomerMiddlename',
267+
'setCustomerFirstname',
268+
'setCustomerLastname',
269+
'setCustomerMiddlename'
258270
]
259271
)
260272
->onlyMethods(
@@ -301,6 +313,9 @@ protected function setUp(): void
301313
$this->lockManagerMock = $this->getMockBuilder(LockManagerInterface::class)
302314
->getMockForAbstractClass();
303315

316+
$this->cartMutexMock = $this->getMockBuilder(CartMutexInterface::class)
317+
->getMockForAbstractClass();
318+
304319
$this->model = $objectManager->getObject(
305320
QuoteManagement::class,
306321
[
@@ -846,6 +861,9 @@ public function testPlaceOrderIfCustomerIsGuest(?string $settledEmail, int $coun
846861
$orderIncrementId = 100003332;
847862
$orderStatus = 'status1';
848863
$email = 'email@mail.com';
864+
$firstName = 'TestFirst';
865+
$middleName = 'TestMiddle';
866+
$lastName = 'TestLast';
849867

850868
$this->quoteRepositoryMock->expects($this->once())
851869
->method('getActive')
@@ -870,12 +888,44 @@ public function testPlaceOrderIfCustomerIsGuest(?string $settledEmail, int $coun
870888
->with($email)
871889
->willReturnSelf();
872890

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+
);
874900
$addressMock->expects($this->exactly($countSetAddress))->method('getEmail')->willReturn($email);
875901
$this->quoteMock->expects($this->any())->method('getBillingAddress')->with()->willReturn($addressMock);
876902

877903
$this->quoteMock->expects($this->once())->method('setCustomerIsGuest')->with(true)->willReturnSelf();
878904
$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);
879929
$this->quoteMock->expects($this->once())
880930
->method('setCustomerGroupId')
881931
->with(GroupInterface::NOT_LOGGED_IN_ID);
@@ -908,7 +958,8 @@ public function testPlaceOrderIfCustomerIsGuest(?string $settledEmail, int $coun
908958
'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock,
909959
'addressRepository' => $this->addressRepositoryMock,
910960
'request' => $this->requestMock,
911-
'remoteAddress' => $this->remoteAddressMock
961+
'remoteAddress' => $this->remoteAddressMock,
962+
'cartMutex' => $this->cartMutexMock
912963
]
913964
)
914965
->getMock();
@@ -990,7 +1041,8 @@ public function testPlaceOrder(): void
9901041
'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock,
9911042
'addressRepository' => $this->addressRepositoryMock,
9921043
'request' => $this->requestMock,
993-
'remoteAddress' => $this->remoteAddressMock
1044+
'remoteAddress' => $this->remoteAddressMock,
1045+
'cartMutex' => $this->cartMutexMock
9941046
]
9951047
)
9961048
->getMock();

0 commit comments

Comments
 (0)