public function testGetStock()
 {
     $this->stockCriteriaFactory->expects($this->once())->method('create')->willReturn($this->stockCriteria);
     $this->stockCriteria->expects($this->once())->method('setScopeFilter')->willReturn(null);
     $stockCollection = $this->getMock('\\Magento\\CatalogInventory\\Model\\ResourceModel\\Stock\\Collection', ['getFirstItem', '__wakeup', 'getItems'], [], '', false);
     $stockCollection->expects($this->once())->method('getItems')->willReturn([$this->stock]);
     $this->stockRepository->expects($this->once())->method('getList')->willReturn($stockCollection);
     $this->stock->expects($this->once())->method('getStockId')->willReturn(true);
     $this->assertEquals($this->stock, $this->stockRegistryProvider->getStock($this->scopeId));
 }
 /**
  * @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;
 }