/** * @param int $productId * @param float $qty * @param int $websiteId * @return \Magento\Framework\DataObject */ public function checkQtyIncrements($productId, $qty, $websiteId = null) { if ($websiteId === null) { $websiteId = $this->stockConfiguration->getDefaultScopeId(); } $stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId); return $this->stockStateProvider->checkQtyIncrements($stockItem, $qty); }
/** * @param bool $isChildItem * @param string $expectedMsg * @dataProvider checkQtyIncrementsMsgDataProvider */ public function testCheckQtyIncrementsMsg($isChildItem, $expectedMsg) { $qty = 1; $qtyIncrements = 5; $stockItem = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockItemInterface')->disableOriginalConstructor()->setMethods($this->stockItemMethods)->getMockForAbstractClass(); $stockItem->expects($this->any())->method('getSuppressCheckQtyIncrements')->willReturn(false); $stockItem->expects($this->any())->method('getQtyIncrements')->willReturn($qtyIncrements); $stockItem->expects($this->any())->method('getIsChildItem')->willReturn($isChildItem); $stockItem->expects($this->any())->method('getProductName')->willReturn('Simple Product'); $this->mathDivision->expects($this->any())->method('getExactDivision')->willReturn(1); $result = $this->stockStateProvider->checkQtyIncrements($stockItem, $qty); $this->assertTrue($result->getHasError()); $this->assertEquals($expectedMsg, $result->getMessage()->render()); }
/** * @param StockItemInterface $stockItem * @param mixed $expectedResult * @dataProvider checkQtyIncrementsDataProvider */ public function testCheckQtyIncrements(StockItemInterface $stockItem, $expectedResult) { $this->assertEquals($expectedResult, $this->stockStateProvider->checkQtyIncrements($stockItem, $this->qty)->getHasError()); }