Skip to content

Commit ade5168

Browse files
author
govindasharma974
committed
updated test files
1 parent 6359ac5 commit ade5168

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/ViewTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ViewTest extends TestCase
108108
protected $pageTitleMock;
109109

110110
/**
111-
* @var \Magento\Shipping\Controller\Adminhtml\Order\Creditmemo\View
111+
* @var \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\View
112112
* @var RedirectFactory|MockObject
113113
*/
114114
protected $resultRedirectFactoryMock;

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/ViewTest.php

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Backend\Model\View\Result\Forward;
1414
use Magento\Backend\Model\View\Result\ForwardFactory;
1515
use Magento\Backend\Model\View\Result\Page;
16+
use Magento\Backend\Model\View\Result\Redirect;
17+
use Magento\Backend\Model\View\Result\RedirectFactory;
1618
use Magento\Framework\App\ActionFlag;
1719
use Magento\Framework\App\Request\Http;
1820
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
@@ -82,6 +84,17 @@ class ViewTest extends TestCase
8284
*/
8385
protected $pageTitleMock;
8486

87+
/**
88+
* @var \Magento\Sales\Controller\Adminhtml\Order\Invoice\View
89+
* @var RedirectFactory|MockObject
90+
*/
91+
protected $resultRedirectFactoryMock;
92+
93+
/**
94+
* @var Redirect|MockObject
95+
*/
96+
protected $resultRedirectMock;
97+
8598
/**
8699
* @var View
87100
*/
@@ -194,6 +207,13 @@ protected function setUp(): void
194207
)->disableOriginalConstructor()
195208
->setMethods(['create'])
196209
->getMock();
210+
$this->resultRedirectFactoryMock = $this->getMockBuilder(RedirectFactory::class)
211+
->disableOriginalConstructor()
212+
->setMethods(['create'])
213+
->getMock();
214+
$this->resultRedirectMock = $this->getMockBuilder(Redirect::class)
215+
->disableOriginalConstructor()
216+
->getMock();
197217
$this->invoiceRepository = $this->getMockBuilder(InvoiceRepositoryInterface::class)
198218
->disableOriginalConstructor()
199219
->getMockForAbstractClass();
@@ -203,7 +223,8 @@ protected function setUp(): void
203223
[
204224
'context' => $contextMock,
205225
'resultPageFactory' => $this->resultPageFactoryMock,
206-
'resultForwardFactory' => $this->resultForwardFactoryMock
226+
'resultForwardFactory' => $this->resultForwardFactoryMock,
227+
'resultRedirectFactory' => $this->resultRedirectFactoryMock
207228
]
208229
);
209230

@@ -287,16 +308,32 @@ public function testExecuteNoInvoice()
287308
->method('get')
288309
->willReturn(null);
289310

290-
$resultForward = $this->getMockBuilder(Forward::class)
291-
->disableOriginalConstructor()
292-
->setMethods([])
293-
->getMock();
294-
$resultForward->expects($this->once())->method('forward')->with(('noroute'))->willReturnSelf();
311+
$this->prepareRedirect();
312+
$this->setPath('sales/invoice');
313+
$this->assertInstanceOf(
314+
Redirect::class,
315+
$this->controller->execute()
316+
);
317+
}
295318

296-
$this->resultForwardFactoryMock->expects($this->once())
319+
/**
320+
* prepareRedirect
321+
*/
322+
protected function prepareRedirect()
323+
{
324+
$this->resultRedirectFactoryMock->expects($this->once())
297325
->method('create')
298-
->willReturn($resultForward);
326+
->willReturn($this->resultRedirectMock);
327+
}
299328

300-
$this->assertSame($resultForward, $this->controller->execute());
329+
/**
330+
* @param string $path
331+
* @param array $params
332+
*/
333+
protected function setPath($path, $params = [])
334+
{
335+
$this->resultRedirectMock->expects($this->once())
336+
->method('setPath')
337+
->with($path, $params);
301338
}
302339
}

0 commit comments

Comments
 (0)