57 private $validatorFactoryMock;
62 private $addressFactoryMock;
66 $this->customerRepositoryMock = $this->getMockForAbstractClass(
67 \
Magento\Customer\Api\CustomerRepositoryInterface::class,
75 $this->customerAddressRepositoryMock = $this->getMockForAbstractClass(
76 \
Magento\Customer\Api\AddressRepositoryInterface::class,
84 $this->accountManagementMock = $this->getMockForAbstractClass(
85 \
Magento\Customer\Api\AccountManagementInterface::class,
93 $this->quoteMock = $this->createPartialMock(
95 [
'getId',
'getCustomer',
'getBillingAddress',
'getShippingAddress',
'setCustomer',
'getPasswordHash']
97 $this->quoteAddressMock = $this->createMock(\
Magento\
Quote\Model\
Quote\Address::class);
98 $this->customerMock = $this->getMockForAbstractClass(
99 \
Magento\Customer\Api\Data\CustomerInterface::class,
105 [
'getId',
'getDefaultBilling']
107 $this->customerAddressMock = $this->getMockForAbstractClass(
108 \
Magento\Customer\Api\Data\AddressInterface::class,
116 $this->addressFactoryMock = $this->getMockBuilder(\
Magento\Customer\Model\AddressFactory::class)
117 ->disableOriginalConstructor()
118 ->setMethods([
'create'])
120 $this->validatorFactoryMock = $this->getMockBuilder(\
Magento\Framework\
Validator\Factory::class)
121 ->disableOriginalConstructor()
123 $this->customerManagement = new \Magento\Quote\Model\CustomerManagement(
124 $this->customerRepositoryMock,
125 $this->customerAddressRepositoryMock,
126 $this->accountManagementMock,
127 $this->validatorFactoryMock,
128 $this->addressFactoryMock
134 $this->quoteMock->expects($this->once())
135 ->method(
'getCustomer')
136 ->willReturn($this->customerMock);
137 $this->customerMock->expects($this->atLeastOnce())
140 $this->customerMock->expects($this->atLeastOnce())
141 ->method(
'getDefaultBilling')
142 ->willReturn(100500);
143 $this->quoteMock->expects($this->atLeastOnce())
144 ->method(
'getBillingAddress')
145 ->willReturn($this->quoteAddressMock);
146 $this->quoteMock->expects($this->atLeastOnce())
147 ->method(
'getShippingAddress')
148 ->willReturn($this->quoteAddressMock);
149 $this->quoteMock->expects($this->atLeastOnce())
150 ->method(
'setCustomer')
151 ->with($this->customerMock)
153 $this->quoteMock->expects($this->once())
154 ->method(
'getPasswordHash')
155 ->willReturn(
'password hash');
156 $this->quoteAddressMock->expects($this->atLeastOnce())
159 $this->customerAddressRepositoryMock->expects($this->atLeastOnce())
162 ->willReturn($this->customerAddressMock);
163 $this->quoteAddressMock->expects($this->atLeastOnce())
164 ->method(
'importCustomerAddressData')
166 $this->accountManagementMock->expects($this->once())
167 ->method(
'createAccountWithPasswordHash')
168 ->with($this->customerMock,
'password hash')
169 ->willReturn($this->customerMock);
170 $this->customerManagement->populateCustomerInfo($this->quoteMock);
175 $this->quoteMock->expects($this->once())
176 ->method(
'getCustomer')
177 ->willReturn($this->customerMock);
178 $this->customerMock->expects($this->atLeastOnce())
181 $this->customerMock->expects($this->atLeastOnce())
182 ->method(
'getDefaultBilling')
183 ->willReturn(100500);
184 $this->quoteMock->expects($this->atLeastOnce())
185 ->method(
'getBillingAddress')
186 ->willReturn($this->quoteAddressMock);
187 $this->quoteMock->expects($this->atLeastOnce())
188 ->method(
'getShippingAddress')
189 ->willReturn($this->quoteAddressMock);
190 $this->quoteAddressMock->expects($this->atLeastOnce())
193 $this->customerAddressRepositoryMock->expects($this->atLeastOnce())
196 ->willReturn($this->customerAddressMock);
197 $this->quoteAddressMock->expects($this->atLeastOnce())
198 ->method(
'importCustomerAddressData')
200 $this->customerManagement->populateCustomerInfo($this->quoteMock);
206 ->expects($this->exactly(2))
207 ->method(
'getBillingAddress')
208 ->willReturn($this->quoteAddressMock);
210 ->expects($this->exactly(2))
211 ->method(
'getShippingAddress')
212 ->willReturn($this->quoteAddressMock);
213 $this->quoteAddressMock->expects($this->any())->method(
'getCustomerAddressId')->willReturn(2);
214 $this->customerAddressRepositoryMock
215 ->expects($this->any())
217 ->willReturn($this->customerAddressMock);
218 $validatorMock = $this->getMockBuilder(\
Magento\Framework\Validator::class)
219 ->disableOriginalConstructor()
221 $addressMock = $this->getMockBuilder(\
Magento\Customer\Model\Address::class)
222 ->disableOriginalConstructor()
224 $this->addressFactoryMock->expects($this->exactly(2))->method(
'create')->willReturn($addressMock);
225 $this->validatorFactoryMock
226 ->expects($this->exactly(2))
227 ->method(
'createValidator')
228 ->with(
'customer_address',
'save',
null)
229 ->willReturn($validatorMock);
230 $validatorMock->expects($this->exactly(2))->method(
'isValid')->with($addressMock)->willReturn(
true);
231 $this->customerManagement->validateAddresses($this->quoteMock);
237 ->expects($this->once())
238 ->method(
'getBillingAddress')
239 ->willReturn($this->quoteAddressMock);
241 ->expects($this->once())
242 ->method(
'getShippingAddress')
243 ->willReturn($this->quoteAddressMock);
244 $this->quoteAddressMock->expects($this->any())->method(
'getCustomerAddressId')->willReturn(
null);
245 $this->validatorFactoryMock
246 ->expects($this->never())
247 ->method(
'createValidator')
248 ->with(
'customer_address',
'save',
null);
249 $this->customerManagement->validateAddresses($this->quoteMock);
$customerAddressRepositoryMock
testValidateAddressesNotSavedInAddressBook()
testPopulateCustomerInfo()
testPopulateCustomerInfoForExistingCustomer()