/** * {@inheritdoc} */ public function dispatch(\Magento\Framework\App\RequestInterface $request) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'dispatch'); if (!$pluginInfo) { return parent::dispatch($request); } else { return $this->___callPlugins('dispatch', func_get_args(), $pluginInfo); } }
/** * @return void */ public function testExecuteModelException() { $invoiceId = 2; $message = 'test message'; $e = new \Magento\Framework\Exception\LocalizedException(__($message)); $this->requestMock->expects($this->once()) ->method('getParam') ->with('invoice_id') ->will($this->returnValue($invoiceId)); $this->invoiceManagement->expects($this->once()) ->method('setVoid') ->with($invoiceId) ->will($this->throwException($e)); $invoiceMock = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice') ->disableOriginalConstructor() ->getMock(); $invoiceMock->expects($this->once()) ->method('getEntityId') ->will($this->returnValue($invoiceId)); $invoiceMock->expects($this->once()) ->method('getId') ->will($this->returnValue($invoiceId)); $invoiceRepository = $this->getMockBuilder('Magento\Sales\Api\InvoiceRepositoryInterface') ->disableOriginalConstructor() ->getMock(); $invoiceRepository->expects($this->any()) ->method('get') ->willReturn($invoiceMock); $this->objectManagerMock->expects($this->once()) ->method('create') ->with('Magento\Sales\Api\InvoiceRepositoryInterface') ->willReturn($invoiceRepository); $this->messageManagerMock->expects($this->once()) ->method('addError'); $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); $resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]); $this->resultRedirectFactoryMock->expects($this->once()) ->method('create') ->will($this->returnValue($resultRedirect)); $this->assertSame($resultRedirect, $this->controller->executeInternal()); }
public function testExecuteException() { $message = 'Cannot update item quantity.'; $e = new \Exception($message); $response = ['error' => true, 'message' => $message]; $this->titleMock->expects($this->once())->method('add')->with('Invoices')->will($this->throwException($e)); $this->responseMock->expects($this->once())->method('representJson')->with(json_encode($response)); $helperMock = $this->getMockBuilder('Magento\\Core\\Helper\\Data')->disableOriginalConstructor()->setMethods([])->getMock(); $helperMock->expects($this->once())->method('jsonEncode')->with($response)->will($this->returnValue(json_encode($response))); $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Core\\Helper\\Data')->will($this->returnValue($helperMock)); $this->assertNull($this->controller->execute()); }
public function testExecuteException() { $orderId = 1; $invoiceId = 2; $invoiceData = []; $message = 'test message'; $e = new \Exception($message); $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId)); $this->requestMock->expects($this->at(1))->method('getParam')->with('invoice_id')->will($this->returnValue($invoiceId)); $this->requestMock->expects($this->at(2))->method('getParam')->with('invoice')->will($this->returnValue($invoiceData)); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $invoiceMock->expects($this->once())->method('void')->will($this->throwException($e)); $this->invoiceLoaderMock->expects($this->once())->method('load')->with($orderId, $invoiceId, $invoiceData)->will($this->returnValue($invoiceMock)); $this->assertNull($this->controller->execute()); }
/** * Test execute exception * * @return void */ public function testExecuteException() { $message = 'The order no longer exists.'; $response = ['error' => true, 'message' => $message]; $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['load', 'getId', 'canInvoice'])->getMock(); $orderMock->expects($this->once())->method('load')->will($this->returnSelf()); $orderMock->expects($this->once())->method('getId')->willReturn(null); $this->objectManagerMock->expects($this->at(0))->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($orderMock); $this->titleMock->expects($this->never())->method('prepend')->with('Invoices'); /** @var \Magento\Framework\Controller\Result\Json|\PHPUnit_Framework_MockObject_MockObject */ $resultJsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->setMethods([])->getMock(); $resultJsonMock->expects($this->once())->method('setData')->with($response); $this->resultJsonFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultJsonMock)); $this->assertSame($resultJsonMock, $this->controller->execute()); }
public function testExecuteModelException() { $invoiceId = 2; $message = 'test message'; $e = new \Magento\Framework\Model\Exception($message); $this->requestMock->expects($this->once())->method('getParam')->with('invoice_id')->will($this->returnValue($invoiceId)); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $invoiceMock->expects($this->once())->method('load')->with($invoiceId)->willReturnSelf(); $invoiceMock->expects($this->once())->method('void')->will($this->throwException($e)); $invoiceMock->expects($this->once())->method('getId')->will($this->returnValue($invoiceId)); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Order\\Invoice')->willReturn($invoiceMock); $this->messageManagerMock->expects($this->once())->method('addError'); $resultRedirect = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->setMethods([])->getMock(); $resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]); $this->resultRedirectFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRedirect)); $this->assertSame($resultRedirect, $this->controller->execute()); }