/**
  * @param int $productId
  * @param int $scopeId
  * @return \Magento\CatalogInventory\Api\Data\StockStatusInterface
  */
 public function getStockStatus($productId, $scopeId)
 {
     $key = $scopeId . '/' . $productId;
     if (!isset($this->stockStatuses[$key])) {
         $criteria = $this->stockStatusCriteriaFactory->create();
         $criteria->setProductsFilter($productId);
         $criteria->setScopeFilter($scopeId);
         $collection = $this->stockStatusRepository->getList($criteria);
         $stockStatus = current($collection->getItems());
         if ($stockStatus && $stockStatus->getProductId()) {
             $this->stockStatuses[$key] = $stockStatus;
         } else {
             return $this->stockStatusFactory->create();
         }
     }
     return $this->stockStatuses[$key];
 }
 /**
  * @param int $productId
  * @param int $scopeId
  * @return \Magento\CatalogInventory\Api\Data\StockStatusInterface
  */
 public function getStockStatus($productId, $scopeId)
 {
     $stockStatus = $this->stockRegistryStorage->getStockStatus($productId, $scopeId);
     if (null === $stockStatus) {
         $criteria = $this->stockStatusCriteriaFactory->create();
         $criteria->setProductsFilter($productId);
         $criteria->setScopeFilter($scopeId);
         $collection = $this->stockStatusRepository->getList($criteria);
         $stockStatus = current($collection->getItems());
         if ($stockStatus && $stockStatus->getProductId()) {
             $this->stockRegistryStorage->setStockStatus($productId, $scopeId, $stockStatus);
         } else {
             $stockStatus = $this->stockStatusFactory->create();
         }
     }
     return $stockStatus;
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->stock = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\Data\\StockInterface', ['__wakeup', 'getStockId'], '', false);
     $this->stockItem = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\Data\\StockItemInterface', ['__wakeup', 'getItemId'], '', false);
     $this->stockStatus = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\Data\\StockStatusInterface', ['__wakeup', 'getProductId'], '', false);
     $this->stockFactory = $this->getMock('\\Magento\\CatalogInventory\\Api\\Data\\StockInterfaceFactory', ['create'], [], '', false);
     $this->stockFactory->expects($this->any())->method('create')->willReturn($this->stock);
     $this->stockItemFactory = $this->getMock('\\Magento\\CatalogInventory\\Api\\Data\\StockItemInterfaceFactory', ['create'], [], '', false);
     $this->stockItemFactory->expects($this->any())->method('create')->willReturn($this->stockItem);
     $this->stockStatusFactory = $this->getMock('\\Magento\\CatalogInventory\\Api\\Data\\StockStatusInterfaceFactory', ['create'], [], '', false);
     $this->stockStatusFactory->expects($this->any())->method('create')->willReturn($this->stockStatus);
     $this->stockRepository = $this->getMockBuilder('\\Magento\\CatalogInventory\\Api\\StockRepositoryInterface')->disableOriginalConstructor()->getMock();
     $this->stockItemRepository = $this->getMockBuilder('\\Magento\\CatalogInventory\\Api\\StockItemRepositoryInterface')->disableOriginalConstructor()->getMock();
     $this->stockStatusRepository = $this->getMockBuilder('\\Magento\\CatalogInventory\\Api\\StockStatusRepositoryInterface')->disableOriginalConstructor()->getMock();
     $this->stockCriteriaFactory = $this->getMock('Magento\\CatalogInventory\\Api\\StockCriteriaInterfaceFactory', ['create'], [], '', false);
     $this->stockCriteria = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\StockCriteriaInterface', ['setScopeFilter'], '', false);
     $this->stockItemCriteriaFactory = $this->getMock('Magento\\CatalogInventory\\Api\\StockItemCriteriaInterfaceFactory', ['create'], [], '', false);
     $this->stockItemCriteria = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\StockItemCriteriaInterface', ['setProductsFilter', 'setScopeFilter'], '', false);
     $this->stockStatusCriteriaFactory = $this->getMock('Magento\\CatalogInventory\\Api\\StockStatusCriteriaInterfaceFactory', ['create'], [], '', false);
     $this->stockStatusCriteria = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\StockStatusCriteriaInterface', ['setProductsFilter', 'setScopeFilter'], '', false);
     $this->stockRegistryProvider = $this->objectManagerHelper->getObject('\\Magento\\CatalogInventory\\Model\\StockRegistryProvider', ['stockRepository' => $this->stockRepository, 'stockFactory' => $this->stockFactory, 'stockItemRepository' => $this->stockItemRepository, 'stockItemFactory' => $this->stockItemFactory, 'stockStatusRepository' => $this->stockStatusRepository, 'stockStatusFactory' => $this->stockStatusFactory, 'stockCriteriaFactory' => $this->stockCriteriaFactory, 'stockItemCriteriaFactory' => $this->stockItemCriteriaFactory, 'stockStatusCriteriaFactory' => $this->stockStatusCriteriaFactory]);
 }