protected function setUp() { $this->objectManagerHelper = new ObjectManagerHelper($this); $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', ['__wakeup', 'getIdBySku'], [], '', false); $this->product->expects($this->any())->method('getIdBySku')->willReturn($this->productId); //getIdBySku $this->productFactory = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false); $this->productFactory->expects($this->any())->method('create')->will($this->returnValue($this->product)); $this->stock = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\Data\\StockInterface', ['__wakeup'], '', false); $this->stockItem = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockItemInterface')->setMethods(['setProductId', 'getData', 'addData', 'getItemId'])->disableOriginalConstructor()->getMockForAbstractClass(); $this->stockStatus = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\Data\\StockStatusInterface', ['__wakeup'], '', false); $this->stockRegistryProvider = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Model\\Spi\\StockRegistryProviderInterface', ['getStock', 'getStockItem', 'getStockStatus'], '', false); $this->stockRegistryProvider->expects($this->any())->method('getStock')->will($this->returnValue($this->stock)); $this->stockRegistryProvider->expects($this->any())->method('getStockItem')->will($this->returnValue($this->stockItem)); $this->stockRegistryProvider->expects($this->any())->method('getStockStatus')->will($this->returnValue($this->stockStatus)); $this->stockItemRepository = $this->getMockForAbstractClass('\\Magento\\CatalogInventory\\Api\\StockItemRepositoryInterface', ['save'], '', false); $this->stockItemRepository->expects($this->any())->method('save')->will($this->returnValue($this->stockItem)); $this->stockRegistry = $this->objectManagerHelper->getObject('\\Magento\\CatalogInventory\\Model\\StockRegistry', ['stockRegistryProvider' => $this->stockRegistryProvider, 'productFactory' => $this->productFactory, 'stockItemRepository' => $this->stockItemRepository]); }
public function testGetStockItem() { $this->stockItemCriteriaFactory->expects($this->once())->method('create')->willReturn($this->stockItemCriteria); $this->stockItemCriteria->expects($this->once())->method('setProductsFilter')->willReturn(null); $stockItemCollection = $this->getMock('\\Magento\\CatalogInventory\\Model\\ResourceModel\\Stock\\Item\\Collection', ['getFirstItem', '__wakeup', 'getItems'], [], '', false); $stockItemCollection->expects($this->once())->method('getItems')->willReturn([$this->stockItem]); $this->stockItemRepository->expects($this->once())->method('getList')->willReturn($stockItemCollection); $this->stockItem->expects($this->once())->method('getItemId')->willReturn(true); $this->assertEquals($this->stockItem, $this->stockRegistryProvider->getStockItem($this->productId, $this->scopeId)); }
public function testSave() { $this->stockItemRepository->expects($this->any())->method('save')->willReturn($this->item); $this->assertEquals($this->item, $this->item->save()); }