Skip to content

Commit 720434d

Browse files
committed
Merge remote-tracking branch 'origin/MC-21706' into 2.3-develop-pr35
2 parents 911b031 + e75231f commit 720434d

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

app/code/Magento/Quote/Model/QuoteRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ protected function loadQuote($loadMethod, $loadField, $identifier, array $shared
224224
{
225225
/** @var CartInterface $quote */
226226
$quote = $this->cartFactory->create();
227-
if ($sharedStoreIds && method_exists($quote, 'setSharedStoreIds')) {
227+
if ($sharedStoreIds && is_callable([$quote, 'setSharedStoreIds'])) {
228228
$quote->setSharedStoreIds($sharedStoreIds);
229229
}
230230
$quote->setStoreId($this->storeManager->getStore()->getId())->$loadMethod($identifier);

app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1010
use Magento\Framework\Api\SortOrder;
1111
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
12+
use PHPUnit\Framework\MockObject\Matcher\InvokedCount as InvokedCountMatch;
1213
use Magento\Framework\ObjectManagerInterface;
1314
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1415
use Magento\Quote\Api\Data\CartInterface;
@@ -284,7 +285,14 @@ public function testGetWithSharedStoreIds()
284285
$this->assertEquals($this->quoteMock, $this->model->get($cartId, $sharedStoreIds));
285286
}
286287

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)
288296
{
289297
$cartId = 17;
290298
$customerId = 23;
@@ -298,7 +306,7 @@ public function testGetForCustomer()
298306
$this->storeMock->expects(static::once())
299307
->method('getId')
300308
->willReturn(1);
301-
$this->quoteMock->expects(static::never())
309+
$this->quoteMock->expects($invokeTimes)
302310
->method('setSharedStoreIds');
303311
$this->quoteMock->expects(static::once())
304312
->method('loadByCustomer')
@@ -312,8 +320,27 @@ public function testGetForCustomer()
312320
->method('load')
313321
->with($this->quoteMock);
314322

323+
static::assertEquals($this->quoteMock, $this->model->getForCustomer($customerId, $sharedStoreIds));
315324
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+
];
317344
}
318345

319346
/**

0 commit comments

Comments
 (0)