public function testGetOrderItemFromFactory() { $this->orderItemFactoryMock->expects($this->once())->method('create')->willReturn($this->orderItemMock); $this->orderItemMock->expects($this->once())->method('load')->with(1)->willReturn($this->orderItemMock); $this->item->setOrderItemId(1); $this->assertEquals($this->orderItemMock, $this->item->getOrderItem()); }
/** * Set quantity to invoice item * * @param \Magento\Sales\Model\Order\Invoice\Item $item * @param float $qty * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ protected function setInvoiceItemQuantity(\Magento\Sales\Model\Order\Invoice\Item $item, $qty) { $qty = $item->getOrderItem()->getIsQtyDecimal() ? (double) $qty : (int) $qty; $qty = $qty > 0 ? $qty : 0; /** * Check qty availability */ $qtyToInvoice = sprintf("%F", $item->getOrderItem()->getQtyToInvoice()); $qty = sprintf("%F", $qty); if ($qty > $qtyToInvoice && !$item->getOrderItem()->isDummy()) { throw new \Magento\Framework\Exception\LocalizedException(__('We found an invalid quantity to invoice item "%1".', $item->getName())); } $item->setQty($qty); return $this; }