Skip to content

Commit 129569a

Browse files
author
okarpenko
committed
MAGETWO-37571: [TechDebt] Covered php code after new checkout implementation by unit tests
1 parent 3c66c19 commit 129569a

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class AddressDetailsManagementTest extends \PHPUnit_Framework_TestCase
4444
*/
4545
protected $dataProcessor;
4646

47+
/** @var \Magento\Quote\Model\QuoteRepository|\PHPUnit_Framework_MockObject_MockObject */
48+
protected $quoteRepository;
49+
4750
/**
4851
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
4952
*/
@@ -58,6 +61,7 @@ protected function setUp()
5861
$this->shippingMethodManagement = $this->getMock('\Magento\Quote\Api\ShippingMethodManagementInterface');
5962
$this->addressDetailsFactory = $this->getMock('\Magento\Quote\Model\AddressDetailsFactory', [], [], '', false);
6063
$this->dataProcessor = $this->getMock('\Magento\Quote\Model\AddressAdditionalDataProcessor', [], [], '', false);
64+
$this->quoteRepository = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false);
6165

6266
$this->model = $this->objectManager->getObject(
6367
'Magento\Quote\Model\AddressDetailsManagement',
@@ -67,7 +71,8 @@ protected function setUp()
6771
'paymentMethodManagement' => $this->paymentMethodManagement,
6872
'shippingMethodManagement' => $this->shippingMethodManagement,
6973
'addressDetailsFactory' => $this->addressDetailsFactory,
70-
'dataProcessor' => $this->dataProcessor
74+
'dataProcessor' => $this->dataProcessor,
75+
'quoteRepository' => $this->quoteRepository,
7176
]
7277
);
7378
}
@@ -125,6 +130,16 @@ public function testSaveAddresses()
125130
->willReturnSelf();
126131
$this->dataProcessor->expects($this->once())->method('process')->with($additionalData);
127132

128-
$this->model->saveAddresses($cartId, $billingAddressMock, $shippingAddressMock, $additionalData);
133+
$quote = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false);
134+
$quote->expects($this->once())
135+
->method('setCheckoutMethod')
136+
->willReturnSelf();
137+
138+
$this->quoteRepository
139+
->expects($this->once())
140+
->method('getActive')
141+
->willReturn($quote);
142+
143+
$this->model->saveAddresses($cartId, $billingAddressMock, $shippingAddressMock, $additionalData, 'register');
129144
}
130145
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ protected function setUp()
200200
'getBillingAddress',
201201
'setCustomerIsGuest',
202202
'setCustomerGroupId',
203-
'assignCustomer'
203+
'assignCustomer',
204+
'getPayment',
204205
],
205206
[],
206207
'',
@@ -769,6 +770,15 @@ public function testPlaceOrder()
769770
->with($cartId)
770771
->willReturn($this->quoteMock);
771772

773+
$quotePayment = $this->getMock('Magento\Quote\Model\Quote\Payment', [], [], '', false);
774+
$quotePayment->expects($this->once())
775+
->method('setQuote');
776+
$quotePayment->expects($this->once())
777+
->method('importData');
778+
$this->quoteMock->expects($this->atLeastOnce())
779+
->method('getPayment')
780+
->willReturn($quotePayment);
781+
772782
$this->quoteMock->expects($this->once())
773783
->method('getCheckoutMethod')
774784
->willReturn(\Magento\Checkout\Model\Type\Onepage::METHOD_CUSTOMER);
@@ -787,7 +797,12 @@ public function testPlaceOrder()
787797
$this->checkoutSessionMock->expects($this->once())->method('setLastOrderId')->with($orderId);
788798
$this->checkoutSessionMock->expects($this->once())->method('setLastRealOrderId')->with($orderIncrementId);
789799
$this->agreementsValidatorMock->expects($this->once())->method('isValid')->willReturn(true);
790-
$this->assertEquals($orderId, $service->placeOrder($cartId));
800+
801+
$paymentMethod = $this->getMock('Magento\Quote\Model\Quote\Payment', ['setChecks', 'getData'], [], '', false);
802+
$paymentMethod->expects($this->once())->method('setChecks');
803+
$paymentMethod->expects($this->once())->method('getData')->willReturn(['additional_data' => []]);
804+
805+
$this->assertEquals($orderId, $service->placeOrder($cartId, null, $paymentMethod));
791806
}
792807

793808
/**

0 commit comments

Comments
 (0)