32 private $cartManagementMock;
37 private $agreementsValidatorMock;
42 private $customerSessionMock;
47 private $checkoutHelperMock;
52 private $billingAddressMock;
61 $this->cartManagementMock = $this->getMockBuilder(CartManagementInterface::class)
62 ->getMockForAbstractClass();
63 $this->agreementsValidatorMock = $this->getMockBuilder(AgreementsValidatorInterface::class)
64 ->getMockForAbstractClass();
65 $this->customerSessionMock = $this->getMockBuilder(Session::class)
66 ->disableOriginalConstructor()
68 $this->checkoutHelperMock = $this->getMockBuilder(Data::class)
69 ->disableOriginalConstructor()
73 $this->cartManagementMock,
74 $this->agreementsValidatorMock,
75 $this->customerSessionMock,
76 $this->checkoutHelperMock
83 $quoteMock = $this->getQuoteMock();
85 $this->agreementsValidatorMock->expects(self::once())
89 $this->getCheckoutMethodStep($quoteMock);
90 $this->prepareGuestQuoteStep($quoteMock);
91 $this->disabledQuoteAddressValidationStep($quoteMock);
93 $quoteMock->expects(self::once())
94 ->method(
'collectTotals');
96 $quoteMock->expects(self::once())
100 $this->cartManagementMock->expects(self::once())
101 ->method(
'placeOrder')
104 $this->orderPlace->execute($quoteMock,
$agreement);
110 private function disabledQuoteAddressValidationStep(\PHPUnit_Framework_MockObject_MockObject $quoteMock)
112 $billingAddressMock = $this->getBillingAddressMock($quoteMock);
113 $shippingAddressMock = $this->getMockBuilder(Address::class)
114 ->setMethods([
'setShouldIgnoreValidation'])
115 ->disableOriginalConstructor()
118 $quoteMock->expects(self::once())
119 ->method(
'getShippingAddress')
120 ->willReturn($shippingAddressMock);
122 $billingAddressMock->expects(self::once())
123 ->method(
'setShouldIgnoreValidation')
127 $quoteMock->expects(self::once())
128 ->method(
'getIsVirtual')
131 $shippingAddressMock->expects(self::once())
132 ->method(
'setShouldIgnoreValidation')
136 $billingAddressMock->expects(self::any())
138 ->willReturn(self::TEST_EMAIL);
140 $billingAddressMock->expects(self::never())
141 ->method(
'setSameAsBilling');
147 private function getCheckoutMethodStep(\PHPUnit_Framework_MockObject_MockObject $quoteMock)
149 $this->customerSessionMock->expects(self::once())
150 ->method(
'isLoggedIn')
153 $quoteMock->expects(self::at(1))
154 ->method(
'getCheckoutMethod')
157 $this->checkoutHelperMock->expects(self::once())
158 ->method(
'isAllowedGuestCheckout')
162 $quoteMock->expects(self::once())
163 ->method(
'setCheckoutMethod')
166 $quoteMock->expects(self::at(2))
167 ->method(
'getCheckoutMethod')
174 private function prepareGuestQuoteStep(\PHPUnit_Framework_MockObject_MockObject $quoteMock)
176 $billingAddressMock = $this->getBillingAddressMock($quoteMock);
178 $quoteMock->expects(self::once())
179 ->method(
'setCustomerId')
183 $billingAddressMock->expects(self::at(0))
185 ->willReturn(self::TEST_EMAIL);
187 $quoteMock->expects(self::once())
188 ->method(
'setCustomerEmail')
189 ->with(self::TEST_EMAIL)
192 $quoteMock->expects(self::once())
193 ->method(
'setCustomerIsGuest')
197 $quoteMock->expects(self::once())
198 ->method(
'setCustomerGroupId')
207 private function getBillingAddressMock(\PHPUnit_Framework_MockObject_MockObject $quoteMock)
209 if (!isset($this->billingAddressMock)) {
210 $this->billingAddressMock = $this->getMockBuilder(Address::class)
211 ->setMethods([
'setShouldIgnoreValidation',
'getEmail',
'setSameAsBilling'])
212 ->disableOriginalConstructor()
216 $quoteMock->expects(self::any())
217 ->method(
'getBillingAddress')
218 ->willReturn($this->billingAddressMock);
220 return $this->billingAddressMock;
226 private function getQuoteMock()
228 return $this->getMockBuilder(Quote::class)
233 'setCustomerIsGuest',
234 'setCustomerGroupId',
240 'getShippingAddress',
243 )->disableOriginalConstructor()