@@ -86,6 +86,16 @@ class QuoteTest extends \PHPUnit_Framework_TestCase
86
86
*/
87
87
protected $ groupManagementMock ;
88
88
89
+ /**
90
+ * @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject
91
+ */
92
+ protected $ billingAddressMock ;
93
+
94
+ /**
95
+ * @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject
96
+ */
97
+ protected $ shippingAddressMock ;
98
+
89
99
/**
90
100
* Set up
91
101
*
@@ -215,9 +225,13 @@ protected function setUp()
215
225
/**
216
226
* Run test getQuote method
217
227
*
228
+ * @param \Magento\Quote\Model\Quote\Address[] $allAddresses
229
+ * @param \Magento\Quote\Model\Quote\Address|null $expectedBillingAddress
230
+ * @param \Magento\Quote\Model\Quote\Address|null $expectedShippingAddress
218
231
* @return void
232
+ * @dataProvider allAddressesDataProvider
219
233
*/
220
- public function testGetQuote ( )
234
+ public function testGetQuoteWithoutQuoteId ( $ allAddresses , $ expectedBillingAddress , $ expectedShippingAddress )
221
235
{
222
236
$ storeId = 10 ;
223
237
$ quoteId = 22 ;
@@ -292,7 +306,7 @@ public function testGetQuote()
292
306
->willReturn ($ dataCustomerMock );
293
307
$ quoteMock ->expects ($ this ->once ())
294
308
->method ('assignCustomerWithAddressChange ' )
295
- ->with ($ dataCustomerMock );
309
+ ->with ($ dataCustomerMock, $ expectedBillingAddress , $ expectedShippingAddress );
296
310
$ quoteMock ->expects ($ this ->once ())
297
311
->method ('setIgnoreOldQty ' )
298
312
->with (true );
@@ -301,17 +315,68 @@ public function testGetQuote()
301
315
->with (true );
302
316
$ quoteMock ->expects ($ this ->any ())
303
317
->method ('getAllAddresses ' )
304
- ->will ($ this ->returnValue ([] ));
318
+ ->will ($ this ->returnValue ($ allAddresses ));
305
319
306
320
$ this ->assertEquals ($ quoteMock , $ this ->quote ->getQuote ());
307
321
}
308
322
323
+ /**
324
+ * @return array
325
+ */
326
+ public function allAddressesDataProvider ()
327
+ {
328
+ // since setup() is called after the dataProvider, ensure we have valid addresses
329
+ $ this ->buildAddressMocks ();
330
+
331
+ return [
332
+ 'empty addresses ' => [
333
+ [],
334
+ null ,
335
+ null
336
+ ],
337
+ 'use typical addresses ' => [
338
+ [$ this ->billingAddressMock , $ this ->shippingAddressMock ],
339
+ $ this ->billingAddressMock ,
340
+ $ this ->shippingAddressMock
341
+ ],
342
+ ];
343
+ }
344
+
345
+ protected function buildAddressMocks ()
346
+ {
347
+ if ($ this ->billingAddressMock == null ) {
348
+ $ this ->billingAddressMock = $ this ->getMock (
349
+ 'Magento\Quote\Model\Quote\Address ' ,
350
+ ['getAddressType ' ],
351
+ [],
352
+ '' ,
353
+ false
354
+ );
355
+ $ this ->billingAddressMock ->expects ($ this ->any ())
356
+ ->method ('getAddressType ' )
357
+ ->will ($ this ->returnValue (\Magento \Quote \Model \Quote \Address::ADDRESS_TYPE_BILLING ));
358
+ }
359
+
360
+ if ($ this ->shippingAddressMock == null ) {
361
+ $ this ->shippingAddressMock = $ this ->getMock (
362
+ 'Magento\Quote\Model\Quote\Address ' ,
363
+ ['getAddressType ' ],
364
+ [],
365
+ '' ,
366
+ false
367
+ );
368
+ $ this ->shippingAddressMock ->expects ($ this ->any ())
369
+ ->method ('getAddressType ' )
370
+ ->will ($ this ->returnValue (\Magento \Quote \Model \Quote \Address::ADDRESS_TYPE_SHIPPING ));
371
+ }
372
+ }
373
+
309
374
/**
310
375
* Run test getQuote method
311
376
*
312
377
* @return void
313
378
*/
314
- public function testGetQuoteGet ()
379
+ public function testGetQuoteWithQuoteId ()
315
380
{
316
381
$ storeId = 10 ;
317
382
$ quoteId = 22 ;
0 commit comments