66 $this->objectManagerHelper =
new ObjectManagerHelper($this);
68 $this->product = $this->createPartialMock(\
Magento\Catalog\Model\Product::class, [
'__wakeup',
'getIdBySku']);
69 $this->product->expects($this->any())
70 ->method(
'getIdBySku')
71 ->willReturn($this->productId);
73 $this->productFactory = $this->createPartialMock(\
Magento\Catalog\Model\ProductFactory::class, [
'create']);
74 $this->productFactory->expects($this->any())
76 ->will($this->returnValue($this->product));
78 $this->stock = $this->getMockForAbstractClass(
79 \
Magento\CatalogInventory\Api\Data\StockInterface::class,
84 $this->stockItem = $this->getMockBuilder(\
Magento\CatalogInventory\Api\Data\StockItemInterface::class)
85 ->setMethods([
'setProductId',
'getData',
'addData',
'getItemId',
'getWebsiteId'])
86 ->disableOriginalConstructor()
87 ->getMockForAbstractClass();
88 $this->stockStatus = $this->getMockForAbstractClass(
89 \
Magento\CatalogInventory\Api\Data\StockStatusInterface::class,
95 $this->stockRegistryProvider = $this->getMockForAbstractClass(
96 \
Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface::class,
97 [
'getStock',
'getStockItem',
'getStockStatus'],
101 $this->stockRegistryProvider->expects($this->any())
103 ->will($this->returnValue($this->stock));
104 $this->stockRegistryProvider->expects($this->any())
105 ->method(
'getStockItem')
106 ->will($this->returnValue($this->stockItem));
107 $this->stockRegistryProvider->expects($this->any())
108 ->method(
'getStockStatus')
109 ->will($this->returnValue($this->stockStatus));
111 $this->stockItemRepository = $this->getMockForAbstractClass(
112 \
Magento\CatalogInventory\Api\StockItemRepositoryInterface::class,
117 $this->stockItemRepository->expects($this->any())
119 ->will($this->returnValue($this->stockItem));
121 $this->stockRegistry = $this->objectManagerHelper->getObject(
122 \
Magento\CatalogInventory\Model\StockRegistry::class,
124 'stockRegistryProvider' => $this->stockRegistryProvider,
125 'productFactory' => $this->productFactory,
126 'stockItemRepository' => $this->stockItemRepository
133 $this->stockRegistry =
null;
138 $this->assertEquals($this->stock, $this->stockRegistry->getStock($this->websiteId));
143 $this->assertEquals($this->stockItem, $this->stockRegistry->getStockItem($this->productId, $this->websiteId));
150 $this->stockRegistry->getStockItemBySku($this->productSku, $this->websiteId)
158 $this->stockRegistry->getStockStatus($this->productId, $this->websiteId)
166 $this->stockRegistry->getStockStatus($this->productId, $this->websiteId)
173 $this->stockItem->expects($this->once())->method(
'setProductId')->willReturnSelf();
174 $this->stockItem->expects($this->once())->method(
'getData')->willReturn([]);
175 $this->stockItem->expects($this->once())->method(
'addData')->willReturnSelf();
176 $this->stockItem->expects($this->atLeastOnce())->method(
'getItemId')->willReturn($itemId);
179 $this->stockRegistry->updateStockItemBySku($this->productSku, $this->stockItem)
testGetStockStatusBySku()
testUpdateStockItemBySku()