@@ -217,12 +217,42 @@ protected function setUp()
217
217
*
218
218
* @return void
219
219
*/
220
- public function testGetQuote ()
220
+ public function testGetQuoteWithoutQuoteId ()
221
221
{
222
- $ storeId = 10 ;
223
222
$ quoteId = 22 ;
224
- $ customerGroupId = 77 ;
223
+ $ storeId = 10 ;
225
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 );
226
256
227
257
$ quoteMock = $ this ->getMock (
228
258
'Magento\Quote\Model\Quote ' ,
@@ -240,28 +270,9 @@ public function testGetQuote()
240
270
'' ,
241
271
false
242
272
);
243
-
244
- $ defaultGroup = $ this ->getMockBuilder ('Magento\Customer\Api\Data\GroupInterface ' )
245
- ->getMock ();
246
- $ defaultGroup ->expects ($ this ->any ())
247
- ->method ('getId ' )
248
- ->will ($ this ->returnValue ($ customerGroupId ));
249
- $ this ->groupManagementMock ->expects ($ this ->any ())
250
- ->method ('getDefaultGroup ' )
251
- ->will ($ this ->returnValue ($ defaultGroup ));
252
-
253
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
254
- ->method ('create ' )
255
- ->will ($ this ->returnValue ($ quoteMock ));
256
- $ this ->quote ->expects ($ this ->any ())
257
- ->method ('getStoreId ' )
258
- ->will ($ this ->returnValue ($ storeId ));
259
273
$ quoteMock ->expects ($ this ->once ())
260
274
->method ('setStoreId ' )
261
275
->with ($ storeId );
262
- $ this ->quote ->expects ($ this ->any ())
263
- ->method ('getQuoteId ' )
264
- ->will ($ this ->returnValue (null ));
265
276
$ quoteMock ->expects ($ this ->once ())
266
277
->method ('setCustomerGroupId ' )
267
278
->with ($ customerGroupId )
@@ -270,25 +281,9 @@ public function testGetQuote()
270
281
->method ('setIsActive ' )
271
282
->with (false )
272
283
->will ($ this ->returnSelf ());
273
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
274
- ->method ('save ' )
275
- ->with ($ quoteMock );
276
284
$ quoteMock ->expects ($ this ->once ())
277
285
->method ('getId ' )
278
286
->will ($ this ->returnValue ($ quoteId ));
279
- $ this ->quote ->expects ($ this ->any ())
280
- ->method ('setQuoteId ' )
281
- ->with ($ quoteId );
282
- $ this ->quote ->expects ($ this ->any ())
283
- ->method ('getCustomerId ' )
284
- ->will ($ this ->returnValue ($ customerId ));
285
- $ dataCustomerMock = $ this ->getMockBuilder ('Magento\Customer\Api\Data\CustomerInterface ' )
286
- ->disableOriginalConstructor ()
287
- ->getMock ();
288
- $ this ->customerRepositoryMock ->expects ($ this ->once ())
289
- ->method ('getById ' )
290
- ->with ($ customerId )
291
- ->willReturn ($ dataCustomerMock );
292
287
$ quoteMock ->expects ($ this ->once ())
293
288
->method ('assignCustomer ' )
294
289
->with ($ dataCustomerMock );
@@ -299,19 +294,47 @@ public function testGetQuote()
299
294
->method ('setIsSuperMode ' )
300
295
->with (true );
301
296
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 );
303
+
302
304
$ this ->assertEquals ($ quoteMock , $ this ->quote ->getQuote ());
303
305
}
304
306
305
307
/**
306
308
* Run test getQuote method
307
309
*
308
310
* @return void
311
+ * @dataProvider getQuoteDataProvider
309
312
*/
310
- public function testGetQuoteGet ( )
313
+ public function testGetQuoteWithQuoteId ( $ customerId , $ quoteCustomerId , $ expectedNumberOfInvokes )
311
314
{
312
- $ storeId = 10 ;
313
315
$ quoteId = 22 ;
314
- $ customerId = 66 ;
316
+ $ storeId = 10 ;
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 ->$ expectedNumberOfInvokes ())
335
+ ->method ('getById ' )
336
+ ->with ($ customerId )
337
+ ->willReturn ($ dataCustomerMock );
315
338
316
339
$ quoteMock = $ this ->getMock (
317
340
'Magento\Quote\Model\Quote ' ,
@@ -323,43 +346,17 @@ public function testGetQuoteGet()
323
346
'assignCustomer ' ,
324
347
'setIgnoreOldQty ' ,
325
348
'setIsSuperMode ' ,
349
+ 'getCustomerId ' ,
326
350
'__wakeup '
327
351
],
328
352
[],
329
353
'' ,
330
354
false
331
355
);
332
-
333
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
334
- ->method ('create ' )
335
- ->will ($ this ->returnValue ($ quoteMock ));
336
- $ this ->quote ->expects ($ this ->any ())
337
- ->method ('getStoreId ' )
338
- ->will ($ this ->returnValue ($ storeId ));
339
356
$ quoteMock ->expects ($ this ->once ())
340
357
->method ('setStoreId ' )
341
358
->with ($ storeId );
342
- $ this ->quote ->expects ($ this ->any ())
343
- ->method ('getQuoteId ' )
344
- ->will ($ this ->returnValue ($ quoteId ));
345
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
346
- ->method ('get ' )
347
- ->with ($ quoteId )
348
- ->willReturn ($ quoteMock );
349
- $ this ->quote ->expects ($ this ->any ())
350
- ->method ('setQuoteId ' )
351
- ->with ($ quoteId );
352
- $ this ->quote ->expects ($ this ->any ())
353
- ->method ('getCustomerId ' )
354
- ->will ($ this ->returnValue ($ customerId ));
355
- $ dataCustomerMock = $ this ->getMockBuilder ('Magento\Customer\Api\Data\CustomerInterface ' )
356
- ->disableOriginalConstructor ()
357
- ->getMock ();
358
- $ this ->customerRepositoryMock ->expects ($ this ->once ())
359
- ->method ('getById ' )
360
- ->with ($ customerId )
361
- ->willReturn ($ dataCustomerMock );
362
- $ quoteMock ->expects ($ this ->once ())
359
+ $ quoteMock ->expects ($ this ->$ expectedNumberOfInvokes ())
363
360
->method ('assignCustomer ' )
364
361
->with ($ dataCustomerMock );
365
362
$ quoteMock ->expects ($ this ->once ())
@@ -368,7 +365,29 @@ public function testGetQuoteGet()
368
365
$ quoteMock ->expects ($ this ->once ())
369
366
->method ('setIsSuperMode ' )
370
367
->with (true );
368
+ $ quoteMock ->expects ($ this ->once ())
369
+ ->method ('getCustomerId ' )
370
+ ->will ($ this ->returnValue ($ quoteCustomerId ));
371
+
372
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
373
+ ->method ('create ' )
374
+ ->will ($ this ->returnValue ($ quoteMock ));
375
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
376
+ ->method ('get ' )
377
+ ->with ($ quoteId )
378
+ ->willReturn ($ quoteMock );
371
379
372
380
$ this ->assertEquals ($ quoteMock , $ this ->quote ->getQuote ());
373
381
}
382
+
383
+ /**
384
+ * @return array
385
+ */
386
+ public function getQuoteDataProvider ()
387
+ {
388
+ return [
389
+ 'customer ids different ' => [66 , null , 'once ' ],
390
+ 'customer ids same ' => [66 , 66 , 'never ' ],
391
+ ];
392
+ }
374
393
}
0 commit comments