/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage We found an invalid quantity to refund item "test". */ public function testRegisterWithException() { $orderItemMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->setMethods(['getQtyRefunded'])->getMock(); $orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(1); $this->item->setQty(2); $this->item->setOrderItem($orderItemMock); $this->item->setName('test'); $result = $this->item->register(); $this->assertInstanceOf('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', $result); }
public function testRegister() { $orderItemMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->getMock(); $orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(1); $orderItemMock->expects($this->once())->method('getTaxRefunded')->willReturn(1); $orderItemMock->expects($this->once())->method('getBaseTaxRefunded')->willReturn(1); $orderItemMock->expects($this->once())->method('getDiscountTaxCompensationRefunded')->willReturn(1); $orderItemMock->expects($this->once())->method('getBaseDiscountTaxCompensationRefunded')->willReturn(1); $orderItemMock->expects($this->once())->method('getAmountRefunded')->willReturn(1); $orderItemMock->expects($this->once())->method('getBaseAmountRefunded')->willReturn(1); $orderItemMock->expects($this->once())->method('getDiscountRefunded')->willReturn(1); $orderItemMock->expects($this->once())->method('getBaseDiscountRefunded')->willReturn(1); $data = ['qty' => 1, 'tax_amount' => 1, 'base_tax_amount' => 1, 'discount_tax_compensation_amount' => 1, 'base_discount_tax_compensation_amount' => 1, 'row_total' => 1, 'base_row_total' => 1, 'discount_amount' => 1, 'base_discount_amount' => 1]; $this->item->setOrderItem($orderItemMock); $this->item->setData($data); $result = $this->item->register(); $this->assertInstanceOf('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', $result); }