/**
  * @param int|null $scopeId
  * @return \Magento\CatalogInventory\Api\Data\StockInterface
  */
 public function getStock($scopeId)
 {
     if (!isset($this->stocks[$scopeId])) {
         $criteria = $this->stockCriteriaFactory->create();
         $criteria->setScopeFilter($scopeId);
         $collection = $this->stockRepository->getList($criteria);
         $stock = current($collection->getItems());
         if ($stock && $stock->getStockId()) {
             $this->stocks[$scopeId] = $stock;
         } else {
             return $this->stockFactory->create();
         }
     }
     return $this->stocks[$scopeId];
 }
 /**
  * @param int|null $scopeId
  * @return \Magento\CatalogInventory\Api\Data\StockInterface
  */
 public function getStock($scopeId)
 {
     $stock = $this->stockRegistryStorage->getStock($scopeId);
     if (null === $stock) {
         $criteria = $this->stockCriteriaFactory->create();
         $criteria->setScopeFilter($scopeId);
         $collection = $this->stockRepository->getList($criteria);
         $stock = current($collection->getItems());
         if ($stock && $stock->getStockId()) {
             $this->stockRegistryStorage->setStock($scopeId, $stock);
         } else {
             $stock = $this->stockFactory->create();
         }
     }
     return $stock;
 }
 /**
  * @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]);
 }