objectManager = new ObjectManager($this); $this->contextMock = $this->getMockBuilder(\Magento\Backend\App\Action\Context::class) ->disableOriginalConstructor() ->getMock(); $this->viewMock = $this->createMock(\Magento\Framework\App\ViewInterface::class); $this->contextMock->expects($this->any()) ->method('getView') ->will($this->returnValue($this->viewMock)); $this->controller = $this->objectManager->getObject( \Magento\Security\Controller\Adminhtml\Session\Activity::class, [ 'context' => $this->contextMock ] ); } /** * @return void */ public function testExecute() { $titleMock = $this->getMockBuilder(\Magento\Framework\View\Page\Title::class) ->disableOriginalConstructor() ->getMock(); $titleMock ->expects($this->once()) ->method('prepend') ->with(new Phrase('Account Activity')); $this->viewMock ->expects($this->any()) ->method('getPage') ->willReturn( new DataObject( ['config' => new DataObject( ['title' => $titleMock] )] ) ); $this->controller->execute(); } }