public function testSave() { $params = []; $stockItemMock = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockItemInterface')->disableOriginalConstructor()->getMock(); $this->indexProcessorMock->expects($this->any())->method('reindexRow')->withAnyParameters(); $this->assertInstanceOf('Magento\\CatalogInventory\\Api\\Data\\StockItemInterface', $this->model->save($stockItemMock, $params)); }
public function testSave() { $productId = 1; $this->stockItemMock->expects($this->any())->method('getProductId')->willReturn($productId); $this->productMock->expects($this->once())->method('load')->with($productId)->willReturnSelf(); $this->productMock->expects($this->once())->method('getId')->willReturn($productId); $this->productMock->expects($this->once())->method('getTypeId')->willReturn('typeId'); $this->stockConfigurationMock->expects($this->once())->method('isQty')->with('typeId')->willReturn(true); $this->stockStateProviderMock->expects($this->once())->method('verifyStock')->with($this->stockItemMock)->willReturn(false); $this->stockItemMock->expects($this->once())->method('getManageStock')->willReturn(true); $this->stockItemMock->expects($this->once())->method('setIsInStock')->with(false)->willReturnSelf(); $this->stockItemMock->expects($this->once())->method('setStockStatusChangedAutomaticallyFlag')->with(true)->willReturnSelf(); $this->stockItemMock->expects($this->any())->method('setLowStockDate')->willReturnSelf(); $this->stockStateProviderMock->expects($this->once())->method('verifyNotification')->with($this->stockItemMock)->willReturn(true); $this->stockItemMock->expects($this->atLeastOnce())->method('setStockStatusChangedAuto')->willReturnSelf(); $this->stockItemMock->expects($this->once())->method('hasStockStatusChangedAutomaticallyFlag')->willReturn(true); $this->stockItemMock->expects($this->once())->method('getStockStatusChangedAutomaticallyFlag')->willReturn(true); $this->stockItemMock->expects($this->once())->method('getWebsiteId')->willReturn(1); $this->stockItemMock->expects($this->once())->method('setWebsiteId')->with(1)->willReturnSelf(); $this->stockItemMock->expects($this->once())->method('getStockId')->willReturn(1); $this->stockItemMock->expects($this->once())->method('setStockId')->with(1)->willReturnSelf(); $this->stockItemResourceMock->expects($this->once())->method('save')->with($this->stockItemMock)->willReturnSelf(); $this->indexProcessorMock->expects($this->once())->method('reindexRow')->with($productId); $this->assertEquals($this->stockItemMock, $this->model->save($this->stockItemMock)); }
public function testRefundOrderInventory() { $websiteId = 0; $ids = ['1', '14']; $items = []; $isAutoReturnEnabled = true; $itemsToUpdate = []; foreach ($ids as $id) { $item = $this->getCreditMemoItem($id); $items[] = $item; $itemsToUpdate[$item->getProductId()] = $item->getQty(); } $creditMemo = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', [], [], '', false); $creditMemo->expects($this->once())->method('getAllItems')->will($this->returnValue($items)); $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId', '__wakeup'], [], '', false); $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId)); $creditMemo->expects($this->once())->method('getStore')->will($this->returnValue($store)); $this->stockConfiguration->expects($this->any())->method('isAutoReturnEnabled')->will($this->returnValue($isAutoReturnEnabled)); $this->stockManagement->expects($this->once())->method('revertProductsSale')->with($itemsToUpdate, $websiteId); $this->stockIndexerProcessor->expects($this->once())->method('reindexList')->with($ids); $this->priceIndexer->expects($this->once())->method('reindexList')->with($ids); $this->event->expects($this->once())->method('getCreditmemo')->will($this->returnValue($creditMemo)); $this->eventObserver->expects($this->atLeastOnce())->method('getEvent')->will($this->returnValue($this->event)); $this->observer->refundOrderInventory($this->eventObserver); }
public function testExecuteThatProductIdsAreObtainedFromAttributeHelper() { $this->attributeHelper->expects($this->any())->method('getProductIds')->will($this->returnValue([5])); $this->attributeHelper->expects($this->any())->method('getSelectedStoreId')->will($this->returnValue([1])); $this->inventoryHelper->expects($this->any())->method('getConfigItemOptions')->will($this->returnValue([])); $this->product->expects($this->any())->method('isProductsHasSku')->with([5])->will($this->returnValue(true)); $this->stockItemService->expects($this->any())->method('getStockItem')->with(5)->will($this->returnValue($this->stockItem)); $this->stockIndexerProcessor->expects($this->any())->method('reindexList')->with([5]); $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['inventory', [], [7]]])); $this->messageManager->expects($this->never())->method('addError'); $this->messageManager->expects($this->never())->method('addException'); $this->object->execute(); }
public function testExecuteThatProductIdsAreObtainedFromAttributeHelper() { $this->attributeHelper->expects($this->any())->method('getProductIds')->will($this->returnValue([5])); $this->attributeHelper->expects($this->any())->method('getSelectedStoreId')->will($this->returnValue([1])); $this->attributeHelper->expects($this->any())->method('getStoreWebsiteId')->will($this->returnValue(1)); $this->stockConfig->expects($this->any())->method('getConfigItemOptions')->will($this->returnValue([])); $this->dataObjectHelperMock->expects($this->any())->method('populateWithArray')->with($this->stockItem, $this->anything(), '\\Magento\\CatalogInventory\\Api\\Data\\StockItemInterface')->willReturnSelf(); $this->product->expects($this->any())->method('isProductsHasSku')->with([5])->will($this->returnValue(true)); $this->stockItemService->expects($this->any())->method('getStockItem')->with(5, 1)->will($this->returnValue($this->stockItem)); $this->stockIndexerProcessor->expects($this->any())->method('reindexList')->with([5]); $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['inventory', [], [7]]])); $this->messageManager->expects($this->never())->method('addError'); $this->messageManager->expects($this->never())->method('addException'); $this->object->execute(); }
public function testExecuteThatProductIdsAreObtainedFromAttributeHelper() { $this->attributeHelper->expects($this->any())->method('getProductIds')->will($this->returnValue([5])); $this->attributeHelper->expects($this->any())->method('getSelectedStoreId')->will($this->returnValue([1])); $this->attributeHelper->expects($this->any())->method('getStoreWebsiteId')->will($this->returnValue(1)); $this->stockConfig->expects($this->any())->method('getConfigItemOptions')->will($this->returnValue([])); $itemToSave = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockItemInterface')->disableOriginalConstructor()->setMethods(['setItemId', 'save'])->getMockForAbstractClass(); $this->stockItemBuilder->expects($this->any())->method('mergeDataObjectWithArray')->withAnyParameters()->willReturnSelf(); $this->stockItemBuilder->expects($this->any())->method('create')->willReturn($itemToSave); $this->product->expects($this->any())->method('isProductsHasSku')->with([5])->will($this->returnValue(true)); $this->stockItemService->expects($this->any())->method('getStockItem')->with(5, 1)->will($this->returnValue($this->stockItem)); $this->stockIndexerProcessor->expects($this->any())->method('reindexList')->with([5]); $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['inventory', [], [7]]])); $this->messageManager->expects($this->never())->method('addError'); $this->messageManager->expects($this->never())->method('addException'); $this->object->execute(); }
/** * @dataProvider saveAndRebuildIndexDataProvider * * @param int $newStockValue new value for stock status * @param int $callCount count matcher */ public function testSaveAndRebuildIndex($newStockValue, $callCount) { $this->model->setValue($newStockValue); $this->stockIndexerProcessor->expects($this->exactly($callCount))->method('markIndexerAsInvalid'); $this->model->afterSave(); }