Skip to content

Commit

Permalink
updated test files
Browse files Browse the repository at this point in the history
  • Loading branch information
govindasharma974 committed Oct 29, 2020
1 parent 6359ac5 commit ade5168
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ViewTest extends TestCase
protected $pageTitleMock;

/**
* @var \Magento\Shipping\Controller\Adminhtml\Order\Creditmemo\View
* @var \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\View
* @var RedirectFactory|MockObject
*/
protected $resultRedirectFactoryMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Magento\Backend\Model\View\Result\Forward;
use Magento\Backend\Model\View\Result\ForwardFactory;
use Magento\Backend\Model\View\Result\Page;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Backend\Model\View\Result\RedirectFactory;
use Magento\Framework\App\ActionFlag;
use Magento\Framework\App\Request\Http;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
Expand Down Expand Up @@ -82,6 +84,17 @@ class ViewTest extends TestCase
*/
protected $pageTitleMock;

/**
* @var \Magento\Sales\Controller\Adminhtml\Order\Invoice\View
* @var RedirectFactory|MockObject
*/
protected $resultRedirectFactoryMock;

/**
* @var Redirect|MockObject
*/
protected $resultRedirectMock;

/**
* @var View
*/
Expand Down Expand Up @@ -194,6 +207,13 @@ protected function setUp(): void
)->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$this->resultRedirectFactoryMock = $this->getMockBuilder(RedirectFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$this->resultRedirectMock = $this->getMockBuilder(Redirect::class)
->disableOriginalConstructor()
->getMock();
$this->invoiceRepository = $this->getMockBuilder(InvoiceRepositoryInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
Expand All @@ -203,7 +223,8 @@ protected function setUp(): void
[
'context' => $contextMock,
'resultPageFactory' => $this->resultPageFactoryMock,
'resultForwardFactory' => $this->resultForwardFactoryMock
'resultForwardFactory' => $this->resultForwardFactoryMock,
'resultRedirectFactory' => $this->resultRedirectFactoryMock
]
);

Expand Down Expand Up @@ -287,16 +308,32 @@ public function testExecuteNoInvoice()
->method('get')
->willReturn(null);

$resultForward = $this->getMockBuilder(Forward::class)
->disableOriginalConstructor()
->setMethods([])
->getMock();
$resultForward->expects($this->once())->method('forward')->with(('noroute'))->willReturnSelf();
$this->prepareRedirect();
$this->setPath('sales/invoice');
$this->assertInstanceOf(
Redirect::class,
$this->controller->execute()
);
}

$this->resultForwardFactoryMock->expects($this->once())
/**
* prepareRedirect
*/
protected function prepareRedirect()
{
$this->resultRedirectFactoryMock->expects($this->once())
->method('create')
->willReturn($resultForward);
->willReturn($this->resultRedirectMock);
}

$this->assertSame($resultForward, $this->controller->execute());
/**
* @param string $path
* @param array $params
*/
protected function setPath($path, $params = [])
{
$this->resultRedirectMock->expects($this->once())
->method('setPath')
->with($path, $params);
}
}

0 comments on commit ade5168

Please sign in to comment.