Skip to content

Commit 87842d3

Browse files
committed
#26065 unit test improve
1 parent ad5c3e4 commit 87842d3

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ protected function getGalleryReadHandler()
592592
* @param \Magento\Catalog\Model\Product $product
593593
* @return \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection
594594
*/
595-
public function getLinkedProductCollection($product)
595+
protected function getLinkedProductCollection($product)
596596
{
597597
$collection = $this->_productCollectionFactory->create()->setFlag(
598598
'product_children',
@@ -767,8 +767,9 @@ public function isSalable($product)
767767
$storeId = $storeId->getId();
768768
}
769769

770-
if (isset($this->isSaleableBySku[$storeId][$product->getSku()])) {
771-
return $this->isSaleableBySku[$storeId][$product->getSku()];
770+
$sku = $product->getSku();
771+
if (isset($this->isSaleableBySku[$storeId][$sku])) {
772+
return $this->isSaleableBySku[$storeId][$sku];
772773
}
773774

774775
$salable = parent::isSalable($product);
@@ -780,7 +781,7 @@ public function isSalable($product)
780781
$salable = 0 !== $collection->getSize();
781782
}
782783

783-
$this->isSaleableBySku[$storeId][$product->getSku()] = $salable;
784+
$this->isSaleableBySku[$storeId][$sku] = $salable;
784785

785786
return $salable;
786787
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,18 @@ public function testHasOptionsFalse()
567567
public function testIsSalable()
568568
{
569569
$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
570-
->setMethods(['__wakeup', 'getStatus', 'hasData', 'getData', 'getStoreId', 'setData'])
570+
->setMethods(['__wakeup', 'getStatus', 'hasData', 'getData', 'getStoreId', 'setData', 'getSku'])
571571
->disableOriginalConstructor()
572572
->getMock();
573+
$productMock
574+
->expects($this->at(0))
575+
->method('getData')
576+
->with('_cache_instance_store_filter')
577+
->willReturn(0);
573578
$productMock->expects($this->once())->method('getStatus')->willReturn(1);
574579
$productMock->expects($this->any())->method('hasData')->willReturn(true);
575-
$productMock->expects($this->at(2))->method('getData')->with('is_salable')->willReturn(true);
580+
$productMock->expects($this->at(1))->method('getSku')->willReturn('SKU-CODE');
581+
$productMock->expects($this->at(4))->method('getData')->with('is_salable')->willReturn(true);
576582
$productCollection = $this->getMockBuilder(
577583
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection::class
578584
)

0 commit comments

Comments
 (0)