Skip to content

Commit

Permalink
magento#26065 unit test improve
Browse files Browse the repository at this point in the history
  • Loading branch information
ilnytskyi committed Jan 22, 2020
1 parent ad5c3e4 commit 87842d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ protected function getGalleryReadHandler()
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection
*/
public function getLinkedProductCollection($product)
protected function getLinkedProductCollection($product)
{
$collection = $this->_productCollectionFactory->create()->setFlag(
'product_children',
Expand Down Expand Up @@ -767,8 +767,9 @@ public function isSalable($product)
$storeId = $storeId->getId();
}

if (isset($this->isSaleableBySku[$storeId][$product->getSku()])) {
return $this->isSaleableBySku[$storeId][$product->getSku()];
$sku = $product->getSku();
if (isset($this->isSaleableBySku[$storeId][$sku])) {
return $this->isSaleableBySku[$storeId][$sku];
}

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

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

return $salable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,18 @@ public function testHasOptionsFalse()
public function testIsSalable()
{
$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->setMethods(['__wakeup', 'getStatus', 'hasData', 'getData', 'getStoreId', 'setData'])
->setMethods(['__wakeup', 'getStatus', 'hasData', 'getData', 'getStoreId', 'setData', 'getSku'])
->disableOriginalConstructor()
->getMock();
$productMock
->expects($this->at(0))
->method('getData')
->with('_cache_instance_store_filter')
->willReturn(0);
$productMock->expects($this->once())->method('getStatus')->willReturn(1);
$productMock->expects($this->any())->method('hasData')->willReturn(true);
$productMock->expects($this->at(2))->method('getData')->with('is_salable')->willReturn(true);
$productMock->expects($this->at(1))->method('getSku')->willReturn('SKU-CODE');
$productMock->expects($this->at(4))->method('getData')->with('is_salable')->willReturn(true);
$productCollection = $this->getMockBuilder(
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection::class
)
Expand Down

0 comments on commit 87842d3

Please sign in to comment.