/** * @return void */ public function testExecute() { $creditmemoId = '111'; $this->requestMock->expects($this->once()) ->method('getParam') ->with('creditmemo_id') ->willReturn($creditmemoId); $this->objectManagerMock->expects($this->once()) ->method('create') ->with('Magento\Sales\Api\CreditmemoManagementInterface') ->willReturn($this->creditmemoManagementMock); $this->creditmemoManagementMock->expects($this->once()) ->method('cancel') ->with($creditmemoId); $this->messageManagerMock->expects($this->once()) ->method('addSuccess') ->with('The credit memo has been canceled.'); $this->resultRedirectFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultRedirectMock); $this->resultRedirectMock->expects($this->once()) ->method('setPath') ->with('sales/*/view', ['creditmemo_id' => $creditmemoId]) ->willReturnSelf(); $this->assertInstanceOf( 'Magento\Backend\Model\View\Result\Redirect', $this->controller->executeInternal() ); }
/** * @param \Magento\Sales\Model\Order\Item $orderItem * @return void */ protected function refundOrder(\Magento\Sales\Model\Order\Item $orderItem) { $creditmemoLoader = $this->creditmemoLoaderFactory->create(); $creditmemoLoader->setOrderId($orderItem->getOrderId()); $creditmemoLoader->setCreditmemo($this->getCreditmemoData($orderItem)); $creditmemo = $creditmemoLoader->load(); if ($creditmemo && $creditmemo->isValidGrandTotal()) { $creditmemo->setOfflineRequested(true); $this->creditmemoManagement->refund($creditmemo, true); } }