/** * @dataProvider testExecuteDataProvider */ public function testExecute($invoice) { $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->getMock(); $blockMock = $this->getMockBuilder('Magento\\Sales\\Block\\Adminhtml\\Order\\Creditmemo\\View')->disableOriginalConstructor()->getMock(); $this->requestMock->expects($this->any())->method('getParam')->withAnyParameters()->willReturnArgument(0); $this->loaderMock->expects($this->once())->method('load')->willReturn($this->creditmemoMock); $this->creditmemoMock->expects($this->any())->method('getInvoice')->willReturn($invoice); $layoutMock->expects($this->once())->method('getBlock')->with('sales_creditmemo_view')->willReturn($blockMock); $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($layoutMock); $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_creditmemo')->willReturnSelf(); $this->resultPageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Page', $this->controller->execute()); }
/** * @dataProvider dataProviderForExecute */ public function testExecuteNoInvoice($invoice) { $this->requestMock->expects($this->any())->method('getParam')->withAnyParameters()->willReturnArgument(0); $this->loaderMock->expects($this->once())->method('load')->willReturn($this->creditmemoMock); $this->creditmemoMock->expects($this->any())->method('getInvoice')->willReturn($invoice); $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods([])->getMock(); $blockMock = $this->getMockBuilder('Magento\\Sales\\Block\\Adminhtml\\Order\\Creditmemo\\View')->disableOriginalConstructor()->setMethods([])->getMock(); $blockMenuMock = $this->getMockBuilder('Magento\\Backend\\Block\\Menu')->disableOriginalConstructor()->setMethods(['getMenuModel', 'setActive', 'getParentItems'])->getMock(); $blockMenuMock->expects($this->any())->method('getMenuModel')->willReturnSelf(); $blockMenuMock->expects($this->any())->method('getParentItems')->willReturn([]); $layoutMock->expects($this->at(0))->method('getBlock')->with('sales_creditmemo_view')->willReturn($blockMock); $layoutMock->expects($this->at(1))->method('getBlock')->with('menu')->willReturn($blockMenuMock); $this->viewMock->expects($this->any())->method('getLayout')->willReturn($layoutMock); $this->assertNull($this->controller->execute()); }