110 $this->objectManagerHelper =
new ObjectManagerHelper($this);
112 $this->stock = $this->getMockForAbstractClass(
113 \
Magento\CatalogInventory\Api\Data\StockInterface::class,
114 [
'__wakeup',
'getStockId'],
118 $this->stockItem = $this->getMockForAbstractClass(
119 \
Magento\CatalogInventory\Api\Data\StockItemInterface::class,
120 [
'__wakeup',
'getItemId'],
124 $this->stockStatus = $this->getMockForAbstractClass(
125 \
Magento\CatalogInventory\Api\Data\StockStatusInterface::class,
126 [
'__wakeup',
'getProductId'],
131 $this->stockFactory = $this->createPartialMock(
132 \
Magento\CatalogInventory\Api\Data\StockInterfaceFactory::class,
135 $this->stockFactory->expects($this->any())->method(
'create')->willReturn($this->stock);
137 $this->stockItemFactory = $this->createPartialMock(
138 \
Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory::class,
141 $this->stockItemFactory->expects($this->any())->method(
'create')->willReturn($this->stockItem);
143 $this->stockStatusFactory = $this->createPartialMock(
144 \
Magento\CatalogInventory\Api\Data\StockStatusInterfaceFactory::class,
147 $this->stockStatusFactory->expects($this->any())->method(
'create')->willReturn($this->stockStatus);
149 $this->stockRepository = $this->getMockBuilder(\
Magento\CatalogInventory\Api\StockRepositoryInterface::class)
150 ->disableOriginalConstructor()
153 $this->stockItemRepository = $this->getMockBuilder(
154 \
Magento\CatalogInventory\Api\StockItemRepositoryInterface::class
156 ->disableOriginalConstructor()
159 $this->stockStatusRepository = $this->getMockBuilder(
160 \
Magento\CatalogInventory\Api\StockStatusRepositoryInterface::class
162 ->disableOriginalConstructor()
165 $this->stockCriteriaFactory = $this->createPartialMock(
166 \
Magento\CatalogInventory\Api\StockCriteriaInterfaceFactory::class,
169 $this->stockCriteria = $this->getMockForAbstractClass(
170 \
Magento\CatalogInventory\Api\StockCriteriaInterface::class,
176 $this->stockItemCriteriaFactory = $this->createPartialMock(
177 \
Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory::class,
180 $this->stockItemCriteria = $this->getMockForAbstractClass(
181 \
Magento\CatalogInventory\Api\StockItemCriteriaInterface::class,
182 [
'setProductsFilter',
'setScopeFilter'],
187 $this->stockStatusCriteriaFactory = $this->createPartialMock(
188 \
Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory::class,
191 $this->stockStatusCriteria = $this->getMockForAbstractClass(
192 \
Magento\CatalogInventory\Api\StockStatusCriteriaInterface::class,
193 [
'setProductsFilter',
'setScopeFilter'],
198 $this->stockRegistryProvider = $this->objectManagerHelper->getObject(
199 \
Magento\CatalogInventory\Model\StockRegistryProvider::class,
201 'stockRepository' => $this->stockRepository,
202 'stockFactory' => $this->stockFactory,
203 'stockItemRepository' => $this->stockItemRepository,
204 'stockItemFactory' => $this->stockItemFactory,
205 'stockStatusRepository' => $this->stockStatusRepository,
206 'stockStatusFactory' => $this->stockStatusFactory,
208 'stockCriteriaFactory' => $this->stockCriteriaFactory,
209 'stockItemCriteriaFactory' => $this->stockItemCriteriaFactory,
210 'stockStatusCriteriaFactory' => $this->stockStatusCriteriaFactory,
211 'stockRegistryStorage' => $this->createMock(\
Magento\CatalogInventory\Model\StockRegistryStorage::class)
218 $this->stockRegistryProvider =
null;
223 $this->stockCriteriaFactory->expects($this->once())->method(
'create')->willReturn($this->stockCriteria);
224 $this->stockCriteria->expects($this->once())->method(
'setScopeFilter')->willReturn(
null);
225 $stockCollection = $this->createPartialMock(
227 [
'getFirstItem',
'__wakeup',
'getItems']
229 $stockCollection->expects($this->once())->method(
'getItems')->willReturn([$this->stock]);
230 $this->stockRepository->expects($this->once())->method(
'getList')->willReturn($stockCollection);
231 $this->stock->expects($this->once())->method(
'getStockId')->willReturn(
true);
232 $this->assertEquals($this->stock, $this->stockRegistryProvider->getStock($this->scopeId));
237 $this->stockItemCriteriaFactory->expects($this->once())->method(
'create')->willReturn($this->stockItemCriteria);
238 $this->stockItemCriteria->expects($this->once())->method(
'setProductsFilter')->willReturn(
null);
239 $stockItemCollection = $this->createPartialMock(
241 [
'getFirstItem',
'__wakeup',
'getItems']
243 $stockItemCollection->expects($this->once())->method(
'getItems')->willReturn([$this->stockItem]);
244 $this->stockItemRepository->expects($this->once())->method(
'getList')->willReturn($stockItemCollection);
245 $this->stockItem->expects($this->once())->method(
'getItemId')->willReturn(
true);
248 $this->stockRegistryProvider->getStockItem($this->productId, $this->scopeId)
254 $this->stockStatusCriteriaFactory->expects($this->once())
256 ->willReturn($this->stockStatusCriteria);
257 $this->stockStatusCriteria->expects($this->once())->method(
'setScopeFilter')->willReturn(
null);
258 $this->stockStatusCriteria->expects($this->once())->method(
'setProductsFilter')->willReturn(
null);
259 $stockStatusCollection = $this->createPartialMock(
261 [
'getFirstItem',
'__wakeup',
'getItems']
263 $stockStatusCollection->expects($this->once())->method(
'getItems')->willReturn([$this->stockStatus]);
264 $this->stockStatusRepository->expects($this->once())->method(
'getList')->willReturn($stockStatusCollection);
265 $this->stockStatus->expects($this->once())->method(
'getProductId')->willReturn($this->productId);
268 $this->stockRegistryProvider->getStockStatus($this->productId, $this->scopeId)
$stockStatusCriteriaFactory
$stockItemCriteriaFactory