contextMock = $this->getMockBuilder(\Magento\Framework\App\Action\Context::class) ->disableOriginalConstructor() ->getMock(); $this->resultPageFactory = $this->getMockBuilder(\Magento\Framework\View\Result\PageFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); $this->controller = new \Magento\Robots\Controller\Index\Index( $this->contextMock, $this->resultPageFactory ); } /** * Check the basic flow of execute() method */ public function testExecute() { $resultPageMock = $this->getMockBuilder(\Magento\Framework\View\Result\Page::class) ->disableOriginalConstructor() ->getMock(); $resultPageMock->expects($this->once()) ->method('addHandle') ->with('robots_index_index'); $resultPageMock->expects($this->once()) ->method('setHeader') ->with('Content-Type', 'text/plain'); $this->resultPageFactory->expects($this->any()) ->method('create') ->with(true) ->willReturn($resultPageMock); $this->assertInstanceOf( \Magento\Framework\View\Result\Page::class, $this->controller->execute() ); } }