91 $this->titleMock = $this->getMockBuilder(\
Magento\Framework\
App\
Action\Title::class)
92 ->disableOriginalConstructor()
96 $this->requestMock = $this->getMockBuilder(\
Magento\Framework\
App\Request\Http::class)
97 ->disableOriginalConstructor()
100 $this->responseMock = $this->getMockBuilder(\
Magento\Framework\
App\
Response\Http::class)
101 ->disableOriginalConstructor()
105 $this->objectManagerMock = $this->createMock(\
Magento\Framework\ObjectManagerInterface::class);
107 $this->messageManagerMock = $this->getMockBuilder(\
Magento\Framework\Message\Manager::class)
108 ->disableOriginalConstructor()
112 $this->actionFlagMock = $this->getMockBuilder(\
Magento\Framework\
App\ActionFlag::class)
113 ->disableOriginalConstructor()
117 $this->helperMock = $this->getMockBuilder(\
Magento\Backend\Helper\Data::class)
118 ->disableOriginalConstructor()
122 $this->sessionMock = $this->getMockBuilder(\
Magento\Backend\Model\Session::class)
123 ->disableOriginalConstructor()
127 $this->resultRedirectFactoryMock = $this->getMockBuilder(
128 \
Magento\Backend\Model\View\Result\RedirectFactory::class
129 )->disableOriginalConstructor()
130 ->setMethods([
'create'])
133 $this->resultForwardFactoryMock = $this->getMockBuilder(
134 \
Magento\Backend\Model\View\Result\ForwardFactory::class
135 )->disableOriginalConstructor()
136 ->setMethods([
'create'])
139 $this->invoiceManagement = $this->getMockBuilder(\
Magento\Sales\Api\InvoiceManagementInterface::class)
140 ->disableOriginalConstructor()
142 $this->objectManagerMock->expects($this->any())
144 ->with(\
Magento\Sales\Api\InvoiceManagementInterface::class)
145 ->willReturn($this->invoiceManagement);
147 $contextMock = $this->getMockBuilder(\
Magento\Backend\
App\
Action\Context::class)
148 ->disableOriginalConstructor()
159 'getResultRedirectFactory' 163 $contextMock->expects($this->any())->method(
'getRequest')->willReturn($this->requestMock);
164 $contextMock->expects($this->any())->method(
'getResponse')->willReturn($this->responseMock);
165 $contextMock->expects($this->any())->method(
'getObjectManager')->willReturn($this->objectManagerMock);
166 $contextMock->expects($this->any())->method(
'getMessageManager')->willReturn($this->messageManagerMock);
167 $contextMock->expects($this->any())->method(
'getTitle')->willReturn($this->titleMock);
168 $contextMock->expects($this->any())->method(
'getActionFlag')->willReturn($this->actionFlagMock);
169 $contextMock->expects($this->any())->method(
'getSession')->willReturn($this->sessionMock);
170 $contextMock->expects($this->any())->method(
'getHelper')->willReturn($this->helperMock);
171 $contextMock->expects($this->any())
172 ->method(
'getResultRedirectFactory')
173 ->willReturn($this->resultRedirectFactoryMock);
175 $this->invoiceRepository = $this->getMockBuilder(InvoiceRepositoryInterface::class)
176 ->disableOriginalConstructor()
177 ->getMockForAbstractClass();
180 \
Magento\Sales\Controller\Adminhtml\Order\Invoice\VoidAction::class,
182 'context' => $contextMock,
183 'resultForwardFactory' => $this->resultForwardFactoryMock
190 $this->invoiceRepository
201 $this->requestMock->expects($this->once())
204 ->will($this->returnValue($invoiceId));
206 $orderMock = $this->getMockBuilder(\
Magento\Sales\Model\Order::class)
207 ->disableOriginalConstructor()
208 ->setMethods([
'setIsInProcess',
'__wakeup'])
211 $this->invoiceManagement->expects($this->once())
216 $invoiceMock = $this->getMockBuilder(\
Magento\Sales\Model\Order\Invoice::class)
217 ->disableOriginalConstructor()
219 $invoiceMock->expects($this->any())
220 ->method(
'getEntityId')
221 ->will($this->returnValue($invoiceId));
222 $invoiceMock->expects($this->any())
224 ->will($this->returnValue($orderMock));
225 $invoiceMock->expects($this->once())
227 ->will($this->returnValue($invoiceId));
229 $transactionMock = $this->getMockBuilder(\
Magento\Framework\DB\Transaction::class)
230 ->disableOriginalConstructor()
232 $transactionMock->expects($this->at(0))
233 ->method(
'addObject')
235 ->will($this->returnSelf());
236 $transactionMock->expects($this->at(1))
237 ->method(
'addObject')
239 ->will($this->returnSelf());
240 $transactionMock->expects($this->at(2))
243 $this->invoiceRepository->expects($this->once())
245 ->willReturn($invoiceMock);
247 $this->objectManagerMock->expects($this->at(1))
249 ->with(\
Magento\Framework\DB\Transaction::class)
250 ->will($this->returnValue($transactionMock));
252 $this->messageManagerMock->expects($this->once())
253 ->method(
'addSuccessMessage')
254 ->with(
'The invoice has been voided.');
256 $resultRedirect = $this->getMockBuilder(\
Magento\Backend\Model\View\Result\Redirect::class)
257 ->disableOriginalConstructor()
260 $resultRedirect->expects($this->once())->method(
'setPath')->with(
'sales/*/view', [
'invoice_id' => $invoiceId]);
262 $this->resultRedirectFactoryMock->expects($this->once())
264 ->will($this->returnValue($resultRedirect));
266 $this->assertSame($resultRedirect, $this->controller->execute());
276 $this->requestMock->expects($this->once())
279 ->will($this->returnValue($invoiceId));
281 $this->invoiceRepository->expects($this->once())
285 $this->messageManagerMock->expects($this->never())
286 ->method(
'addErrorMessage');
287 $this->messageManagerMock->expects($this->never())
288 ->method(
'addSuccessMessage');
290 $resultForward = $this->getMockBuilder(\
Magento\Backend\Model\View\Result\Forward::class)
291 ->disableOriginalConstructor()
294 $resultForward->expects($this->once())->method(
'forward')->with((
'noroute'))->will($this->returnSelf());
296 $this->resultForwardFactoryMock->expects($this->once())
298 ->will($this->returnValue($resultForward));
300 $this->assertSame($resultForward, $this->controller->execute());
310 $e = new \Magento\Framework\Exception\LocalizedException(
__(
$message));
312 $this->requestMock->expects($this->once())
315 ->will($this->returnValue($invoiceId));
317 $this->invoiceManagement->expects($this->once())
320 ->will($this->throwException($e));
322 $invoiceMock = $this->getMockBuilder(\
Magento\Sales\Model\Order\Invoice::class)
323 ->disableOriginalConstructor()
325 $invoiceMock->expects($this->once())
326 ->method(
'getEntityId')
327 ->will($this->returnValue($invoiceId));
328 $invoiceMock->expects($this->once())
330 ->will($this->returnValue($invoiceId));
332 $this->invoiceRepository->expects($this->once())
334 ->willReturn($invoiceMock);
336 $this->messageManagerMock->expects($this->once())
337 ->method(
'addErrorMessage');
339 $resultRedirect = $this->getMockBuilder(\
Magento\Backend\Model\View\Result\Redirect::class)
340 ->disableOriginalConstructor()
343 $resultRedirect->expects($this->once())->method(
'setPath')->with(
'sales/*/view', [
'invoice_id' => $invoiceId]);
345 $this->resultRedirectFactoryMock->expects($this->once())
347 ->will($this->returnValue($resultRedirect));
349 $this->assertSame($resultRedirect, $this->controller->execute());
testExecuteModelException()
$resultForwardFactoryMock
$resultRedirectFactoryMock