public function testExecuteNoOrder() { $orderId = 1; $invoiceData = []; $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', []) ->will($this->returnValue($invoiceData)); $orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->setMethods(['load', 'getId', 'canInvoice']) ->getMock(); $orderMock->expects($this->once()) ->method('load') ->with($orderId) ->willReturnSelf(); $orderMock->expects($this->once()) ->method('getId') ->willReturn(null); $this->objectManagerMock->expects($this->at(0)) ->method('create') ->with('Magento\Sales\Model\Order') ->willReturn($orderMock); $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); $resultRedirect->expects($this->once())->method('setPath')->with('sales/order/view', ['order_id' => $orderId]); $this->resultRedirectFactoryMock->expects($this->once()) ->method('create') ->will($this->returnValue($resultRedirect)); $this->assertSame($resultRedirect, $this->controller->executeInternal()); }