9
9
use Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface ;
10
10
use Magento \Framework \Api \SortOrder ;
11
11
use Magento \Framework \Api \ExtensionAttribute \JoinProcessorInterface ;
12
+ use PHPUnit \Framework \MockObject \Matcher \InvokedCount as InvokedCountMatch ;
12
13
use Magento \Framework \ObjectManagerInterface ;
13
14
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
14
15
use Magento \Quote \Api \Data \CartInterface ;
@@ -284,7 +285,14 @@ public function testGetWithSharedStoreIds()
284
285
$ this ->assertEquals ($ this ->quoteMock , $ this ->model ->get ($ cartId , $ sharedStoreIds ));
285
286
}
286
287
287
- public function testGetForCustomer ()
288
+ /**
289
+ * Test getForCustomer method
290
+ *
291
+ * @param InvokedCountMatch $invokeTimes
292
+ * @param array $sharedStoreIds
293
+ * @dataProvider getForCustomerDataProvider
294
+ */
295
+ public function testGetForCustomer (InvokedCountMatch $ invokeTimes , array $ sharedStoreIds )
288
296
{
289
297
$ cartId = 17 ;
290
298
$ customerId = 23 ;
@@ -298,7 +306,7 @@ public function testGetForCustomer()
298
306
$ this ->storeMock ->expects (static ::once ())
299
307
->method ('getId ' )
300
308
->willReturn (1 );
301
- $ this ->quoteMock ->expects (static :: never () )
309
+ $ this ->quoteMock ->expects ($ invokeTimes )
302
310
->method ('setSharedStoreIds ' );
303
311
$ this ->quoteMock ->expects (static ::once ())
304
312
->method ('loadByCustomer ' )
@@ -312,8 +320,27 @@ public function testGetForCustomer()
312
320
->method ('load ' )
313
321
->with ($ this ->quoteMock );
314
322
323
+ static ::assertEquals ($ this ->quoteMock , $ this ->model ->getForCustomer ($ customerId , $ sharedStoreIds ));
315
324
static ::assertEquals ($ this ->quoteMock , $ this ->model ->getForCustomer ($ customerId ));
316
- static ::assertEquals ($ this ->quoteMock , $ this ->model ->getForCustomer ($ customerId ));
325
+ }
326
+
327
+ /**
328
+ * Checking how many times we invoke setSharedStoreIds() in protected method loadQuote()
329
+ *
330
+ * @return array
331
+ */
332
+ public function getForCustomerDataProvider ()
333
+ {
334
+ return [
335
+ [
336
+ 'invoke_number_times ' => static ::never (),
337
+ 'shared_store_ids ' => []
338
+ ],
339
+ [
340
+ 'invoke_number_times ' => static ::once (),
341
+ 'shared_store_ids ' => [1 ]
342
+ ]
343
+ ];
317
344
}
318
345
319
346
/**
0 commit comments