7
7
8
8
/**
9
9
* Class QuoteTest
10
- *
11
10
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12
- * @SuppressWarnings(PHPMD.TooManyFields)
13
11
*/
14
12
class QuoteTest extends \PHPUnit_Framework_TestCase
15
13
{
@@ -88,16 +86,6 @@ class QuoteTest extends \PHPUnit_Framework_TestCase
88
86
*/
89
87
protected $ groupManagementMock ;
90
88
91
- /**
92
- * @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject
93
- */
94
- protected $ billingAddressMock ;
95
-
96
- /**
97
- * @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject
98
- */
99
- protected $ shippingAddressMock ;
100
-
101
89
/**
102
90
* Set up
103
91
*
@@ -227,18 +215,44 @@ protected function setUp()
227
215
/**
228
216
* Run test getQuote method
229
217
*
230
- * @param \Magento\Quote\Model\Quote\Address[] $allAddresses
231
- * @param \Magento\Quote\Model\Quote\Address|null $expectedBillingAddress
232
- * @param \Magento\Quote\Model\Quote\Address|null $expectedShippingAddress
233
218
* @return void
234
- * @dataProvider allAddressesDataProvider
235
219
*/
236
- public function testGetQuoteWithoutQuoteId ($ allAddresses , $ expectedBillingAddress , $ expectedShippingAddress )
220
+ public function testGetQuoteWithoutQuoteId ()
237
221
{
238
- $ storeId = 10 ;
239
222
$ quoteId = 22 ;
240
- $ customerGroupId = 77 ;
223
+ $ storeId = 10 ;
241
224
$ customerId = 66 ;
225
+ $ customerGroupId = 77 ;
226
+
227
+ $ this ->quote ->expects ($ this ->any ())
228
+ ->method ('getQuoteId ' )
229
+ ->will ($ this ->returnValue (null ));
230
+ $ this ->quote ->expects ($ this ->any ())
231
+ ->method ('setQuoteId ' )
232
+ ->with ($ quoteId );
233
+ $ this ->quote ->expects ($ this ->any ())
234
+ ->method ('getStoreId ' )
235
+ ->will ($ this ->returnValue ($ storeId ));
236
+ $ this ->quote ->expects ($ this ->any ())
237
+ ->method ('getCustomerId ' )
238
+ ->will ($ this ->returnValue ($ customerId ));
239
+
240
+ $ defaultGroup = $ this ->getMockBuilder ('Magento\Customer\Api\Data\GroupInterface ' )
241
+ ->getMock ();
242
+ $ defaultGroup ->expects ($ this ->any ())
243
+ ->method ('getId ' )
244
+ ->will ($ this ->returnValue ($ customerGroupId ));
245
+ $ this ->groupManagementMock ->expects ($ this ->any ())
246
+ ->method ('getDefaultGroup ' )
247
+ ->will ($ this ->returnValue ($ defaultGroup ));
248
+
249
+ $ dataCustomerMock = $ this ->getMockBuilder ('Magento\Customer\Api\Data\CustomerInterface ' )
250
+ ->disableOriginalConstructor ()
251
+ ->getMock ();
252
+ $ this ->customerRepositoryMock ->expects ($ this ->once ())
253
+ ->method ('getById ' )
254
+ ->with ($ customerId )
255
+ ->willReturn ($ dataCustomerMock );
242
256
243
257
$ quoteMock = $ this ->getMock (
244
258
'Magento\Quote\Model\Quote ' ,
@@ -247,38 +261,18 @@ public function testGetQuoteWithoutQuoteId($allAddresses, $expectedBillingAddres
247
261
'setCustomerGroupId ' ,
248
262
'setIsActive ' ,
249
263
'getId ' ,
250
- 'assignCustomerWithAddressChange ' ,
264
+ 'assignCustomer ' ,
251
265
'setIgnoreOldQty ' ,
252
266
'setIsSuperMode ' ,
253
- 'getAllAddresses ' ,
254
267
'__wakeup '
255
268
],
256
269
[],
257
270
'' ,
258
271
false
259
272
);
260
-
261
- $ defaultGroup = $ this ->getMockBuilder ('Magento\Customer\Api\Data\GroupInterface ' )
262
- ->getMock ();
263
- $ defaultGroup ->expects ($ this ->any ())
264
- ->method ('getId ' )
265
- ->will ($ this ->returnValue ($ customerGroupId ));
266
- $ this ->groupManagementMock ->expects ($ this ->any ())
267
- ->method ('getDefaultGroup ' )
268
- ->will ($ this ->returnValue ($ defaultGroup ));
269
-
270
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
271
- ->method ('create ' )
272
- ->will ($ this ->returnValue ($ quoteMock ));
273
- $ this ->quote ->expects ($ this ->any ())
274
- ->method ('getStoreId ' )
275
- ->will ($ this ->returnValue ($ storeId ));
276
273
$ quoteMock ->expects ($ this ->once ())
277
274
->method ('setStoreId ' )
278
275
->with ($ storeId );
279
- $ this ->quote ->expects ($ this ->any ())
280
- ->method ('getQuoteId ' )
281
- ->will ($ this ->returnValue (null ));
282
276
$ quoteMock ->expects ($ this ->once ())
283
277
->method ('setCustomerGroupId ' )
284
278
->with ($ customerGroupId )
@@ -287,90 +281,27 @@ public function testGetQuoteWithoutQuoteId($allAddresses, $expectedBillingAddres
287
281
->method ('setIsActive ' )
288
282
->with (false )
289
283
->will ($ this ->returnSelf ());
290
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
291
- ->method ('save ' )
292
- ->with ($ quoteMock );
293
284
$ quoteMock ->expects ($ this ->once ())
294
285
->method ('getId ' )
295
286
->will ($ this ->returnValue ($ quoteId ));
296
- $ this ->quote ->expects ($ this ->any ())
297
- ->method ('setQuoteId ' )
298
- ->with ($ quoteId );
299
- $ this ->quote ->expects ($ this ->any ())
300
- ->method ('getCustomerId ' )
301
- ->will ($ this ->returnValue ($ customerId ));
302
- $ dataCustomerMock = $ this ->getMockBuilder ('Magento\Customer\Api\Data\CustomerInterface ' )
303
- ->disableOriginalConstructor ()
304
- ->getMock ();
305
- $ this ->customerRepositoryMock ->expects ($ this ->once ())
306
- ->method ('getById ' )
307
- ->with ($ customerId )
308
- ->willReturn ($ dataCustomerMock );
309
287
$ quoteMock ->expects ($ this ->once ())
310
- ->method ('assignCustomerWithAddressChange ' )
311
- ->with ($ dataCustomerMock, $ expectedBillingAddress , $ expectedShippingAddress );
288
+ ->method ('assignCustomer ' )
289
+ ->with ($ dataCustomerMock );
312
290
$ quoteMock ->expects ($ this ->once ())
313
291
->method ('setIgnoreOldQty ' )
314
292
->with (true );
315
293
$ quoteMock ->expects ($ this ->once ())
316
294
->method ('setIsSuperMode ' )
317
295
->with (true );
318
- $ quoteMock ->expects ($ this ->any ())
319
- ->method ('getAllAddresses ' )
320
- ->will ($ this ->returnValue ($ allAddresses ));
321
296
322
- $ this ->assertEquals ($ quoteMock , $ this ->quote ->getQuote ());
323
- }
324
-
325
- /**
326
- * @return array
327
- */
328
- public function allAddressesDataProvider ()
329
- {
330
- // since setup() is called after the dataProvider, ensure we have valid addresses
331
- $ this ->buildAddressMocks ();
332
-
333
- return [
334
- 'empty addresses ' => [
335
- [],
336
- null ,
337
- null
338
- ],
339
- 'use typical addresses ' => [
340
- [$ this ->billingAddressMock , $ this ->shippingAddressMock ],
341
- $ this ->billingAddressMock ,
342
- $ this ->shippingAddressMock
343
- ],
344
- ];
345
- }
297
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
298
+ ->method ('create ' )
299
+ ->will ($ this ->returnValue ($ quoteMock ));
300
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
301
+ ->method ('save ' )
302
+ ->with ($ quoteMock );
346
303
347
- protected function buildAddressMocks ()
348
- {
349
- if ($ this ->billingAddressMock == null ) {
350
- $ this ->billingAddressMock = $ this ->getMock (
351
- 'Magento\Quote\Model\Quote\Address ' ,
352
- ['getAddressType ' ],
353
- [],
354
- '' ,
355
- false
356
- );
357
- $ this ->billingAddressMock ->expects ($ this ->any ())
358
- ->method ('getAddressType ' )
359
- ->will ($ this ->returnValue (\Magento \Quote \Model \Quote \Address::ADDRESS_TYPE_BILLING ));
360
- }
361
-
362
- if ($ this ->shippingAddressMock == null ) {
363
- $ this ->shippingAddressMock = $ this ->getMock (
364
- 'Magento\Quote\Model\Quote\Address ' ,
365
- ['getAddressType ' ],
366
- [],
367
- '' ,
368
- false
369
- );
370
- $ this ->shippingAddressMock ->expects ($ this ->any ())
371
- ->method ('getAddressType ' )
372
- ->will ($ this ->returnValue (\Magento \Quote \Model \Quote \Address::ADDRESS_TYPE_SHIPPING ));
373
- }
304
+ $ this ->assertEquals ($ quoteMock , $ this ->quote ->getQuote ());
374
305
}
375
306
376
307
/**
@@ -380,69 +311,67 @@ protected function buildAddressMocks()
380
311
*/
381
312
public function testGetQuoteWithQuoteId ()
382
313
{
383
- $ storeId = 10 ;
384
314
$ quoteId = 22 ;
315
+ $ storeId = 10 ;
385
316
$ customerId = 66 ;
386
317
318
+ $ this ->quote ->expects ($ this ->any ())
319
+ ->method ('getQuoteId ' )
320
+ ->will ($ this ->returnValue ($ quoteId ));
321
+ $ this ->quote ->expects ($ this ->any ())
322
+ ->method ('setQuoteId ' )
323
+ ->with ($ quoteId );
324
+ $ this ->quote ->expects ($ this ->any ())
325
+ ->method ('getStoreId ' )
326
+ ->will ($ this ->returnValue ($ storeId ));
327
+ $ this ->quote ->expects ($ this ->any ())
328
+ ->method ('getCustomerId ' )
329
+ ->will ($ this ->returnValue ($ customerId ));
330
+
331
+ $ dataCustomerMock = $ this ->getMockBuilder ('Magento\Customer\Api\Data\CustomerInterface ' )
332
+ ->disableOriginalConstructor ()
333
+ ->getMock ();
334
+ $ this ->customerRepositoryMock ->expects ($ this ->once ())
335
+ ->method ('getById ' )
336
+ ->with ($ customerId )
337
+ ->willReturn ($ dataCustomerMock );
338
+
387
339
$ quoteMock = $ this ->getMock (
388
340
'Magento\Quote\Model\Quote ' ,
389
341
[
390
342
'setStoreId ' ,
391
343
'setCustomerGroupId ' ,
392
344
'setIsActive ' ,
393
345
'getId ' ,
394
- 'assignCustomerWithAddressChange ' ,
346
+ 'assignCustomer ' ,
395
347
'setIgnoreOldQty ' ,
396
348
'setIsSuperMode ' ,
397
- 'getAllAddresses ' ,
398
349
'__wakeup '
399
350
],
400
351
[],
401
352
'' ,
402
353
false
403
354
);
404
-
405
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
406
- ->method ('create ' )
407
- ->will ($ this ->returnValue ($ quoteMock ));
408
- $ this ->quote ->expects ($ this ->any ())
409
- ->method ('getStoreId ' )
410
- ->will ($ this ->returnValue ($ storeId ));
411
355
$ quoteMock ->expects ($ this ->once ())
412
356
->method ('setStoreId ' )
413
357
->with ($ storeId );
414
- $ this ->quote ->expects ($ this ->any ())
415
- ->method ('getQuoteId ' )
416
- ->will ($ this ->returnValue ($ quoteId ));
417
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
418
- ->method ('get ' )
419
- ->with ($ quoteId )
420
- ->willReturn ($ quoteMock );
421
- $ this ->quote ->expects ($ this ->any ())
422
- ->method ('setQuoteId ' )
423
- ->with ($ quoteId );
424
- $ this ->quote ->expects ($ this ->any ())
425
- ->method ('getCustomerId ' )
426
- ->will ($ this ->returnValue ($ customerId ));
427
- $ dataCustomerMock = $ this ->getMockBuilder ('Magento\Customer\Api\Data\CustomerInterface ' )
428
- ->disableOriginalConstructor ()
429
- ->getMock ();
430
- $ this ->customerRepositoryMock ->expects ($ this ->once ())
431
- ->method ('getById ' )
432
- ->with ($ customerId )
433
- ->willReturn ($ dataCustomerMock );
434
358
$ quoteMock ->expects ($ this ->once ())
435
- ->method ('assignCustomerWithAddressChange ' )
359
+ ->method ('assignCustomer ' )
436
360
->with ($ dataCustomerMock );
437
361
$ quoteMock ->expects ($ this ->once ())
438
362
->method ('setIgnoreOldQty ' )
439
363
->with (true );
440
364
$ quoteMock ->expects ($ this ->once ())
441
365
->method ('setIsSuperMode ' )
442
366
->with (true );
443
- $ quoteMock ->expects ($ this ->any ())
444
- ->method ('getAllAddresses ' )
445
- ->will ($ this ->returnValue ([]));
367
+
368
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
369
+ ->method ('create ' )
370
+ ->will ($ this ->returnValue ($ quoteMock ));
371
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
372
+ ->method ('get ' )
373
+ ->with ($ quoteId )
374
+ ->willReturn ($ quoteMock );
446
375
447
376
$ this ->assertEquals ($ quoteMock , $ this ->quote ->getQuote ());
448
377
}
0 commit comments