public function testAddInventoryData() { $stockStatus = true; $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['__wakeup', 'getStockStatus'])->getMock(); $product->expects($this->once())->method('getStockStatus')->will($this->returnValue($stockStatus)); $this->event->expects($this->once())->method('getProduct')->will($this->returnValue($product)); $this->stockHelper->expects($this->once())->method('assignStatusToProduct')->with($product, $stockStatus)->will($this->returnSelf()); $this->eventObserver->expects($this->atLeastOnce())->method('getEvent')->will($this->returnValue($this->event)); $this->assertEquals($this->observer, $this->observer->addInventoryData($this->eventObserver)); }
public function testAddInventoryData() { $productId = 4; $stockId = 6; $stockStatus = true; $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['getId', 'getStockStatus', '__wakeup'])->getMock(); $product->expects($this->once())->method('getId')->will($this->returnValue($productId)); $product->expects($this->once())->method('getStockStatus')->will($this->returnValue($stockStatus)); $this->event->expects($this->once())->method('getProduct')->will($this->returnValue($product)); $stockItem = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\Stock\\Item')->disableOriginalConstructor()->getMock(); $stockItem->expects($this->once())->method('getStockId')->will($this->returnValue($stockId)); $this->stockItemRegistry->expects($this->once())->method('retrieve')->with($productId)->will($this->returnValue($stockItem)); $this->stockStatus->expects($this->once())->method('assignProduct')->with($product, $stockId, $stockStatus)->will($this->returnSelf()); $this->assertEquals($this->model, $this->model->addInventoryData($this->eventObserver)); }