protected function setUp() { $this->objectManagerHelper = new ObjectManagerHelper($this); $this->mathDivision = $this->getMock('\\Magento\\Framework\\Math\\Division', ['getExactDivision'], [], '', false); $this->mathDivision->expects($this->any())->method('getExactDivision')->willReturn($this->qtyDivision); $this->localeFormat = $this->getMockForAbstractClass('\\Magento\\Framework\\Locale\\FormatInterface', ['getNumber']); $this->localeFormat->expects($this->any())->method('getNumber')->willReturn($this->qty); $this->object = $this->objectManagerHelper->getObject('Magento\\Framework\\Object'); $this->objectFactory = $this->getMock('\\Magento\\Framework\\Object\\Factory', ['create'], [], '', false); $this->objectFactory->expects($this->any())->method('create')->willReturn($this->object); $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', ['load', 'isComposite', '__wakeup', 'isSaleable'], [], '', false); $this->productFactory = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false); $this->productFactory->expects($this->any())->method('create')->willReturn($this->product); $this->stockStateProvider = $this->objectManagerHelper->getObject('Magento\\CatalogInventory\\Model\\StockStateProvider', ['mathDivision' => $this->mathDivision, 'localeFormat' => $this->localeFormat, 'objectFactory' => $this->objectFactory, 'productFactory' => $this->productFactory, 'qtyCheckApplicable' => $this->qtyCheckApplicable]); }
/** * @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()); }