configMock = $this->getMockBuilder(ConfigInterface::class)->getMockForAbstractClass(); $context = $this->getMockBuilder( \Magento\Framework\App\Action\Context::class )->setMethods( ['getRequest', 'getResponse'] )->disableOriginalConstructor( )->getMock(); $context->expects($this->any()) ->method('getRequest') ->will( $this->returnValue( $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass() ) ); $context->expects($this->any()) ->method('getResponse') ->will( $this->returnValue( $this->getMockBuilder(ResponseInterface::class)->getMockForAbstractClass() ) ); $this->controller = new \Magento\Contact\Test\Unit\Controller\Stub\IndexStub( $context, $this->configMock ); } /** * Dispatch test * * @expectedException \Magento\Framework\Exception\NotFoundException */ public function testDispatch() { $this->configMock->method('isEnabled')->willReturn(false); $this->controller->dispatch( $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass() ); } }