/** * @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->execute()); }
public function testExecute() { $this->requestMock->expects($this->any())->method('getParam')->withAnyParameters()->willReturnArgument(0); $this->loaderMock->expects($this->once())->method('load')->willReturn($this->creditmemoMock); $transactionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Transaction')->disableOriginalConstructor()->setMethods([])->getMock(); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\DB\\Transaction')->willReturn($transactionMock); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods([])->getMock(); $this->creditmemoMock->expects($this->any())->method('getOrder')->willReturn($orderMock); $this->creditmemoMock->expects($this->any())->method('getInvoice')->willReturn($invoiceMock); $this->messageManagerMock->expects($this->once())->method('addSuccess')->with('The credit memo has been canceled.'); $this->assertNull($this->controller->execute()); }
public function testExecute() { $id = '111'; $transactionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Transaction')->disableOriginalConstructor()->getMock(); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->getMock(); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $this->requestMock->expects($this->any())->method('getParam')->willReturnArgument(0); $this->loaderMock->expects($this->once())->method('load')->willReturn($this->creditmemoMock); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\DB\\Transaction')->willReturn($transactionMock); $this->creditmemoMock->expects($this->any())->method('getOrder')->willReturn($orderMock); $this->creditmemoMock->expects($this->any())->method('getInvoice')->willReturn($invoiceMock); $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->creditmemoMock->expects($this->atLeastOnce())->method('getId')->willReturn($id); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/view', ['creditmemo_id' => $id])->willReturnSelf(); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->controller->execute()); }