/** * @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); }