public function testDispatch() { if (!\Magento\TestFramework\Helper\Bootstrap::canTestHeaders()) { $this->markTestSkipped('Can\'t test dispatch process without sending headers'); } $_SERVER['HTTP_HOST'] = 'localhost'; $this->_objectManager->get('Magento\\Framework\\App\\State')->setAreaCode('frontend'); $request = $this->_objectManager->create('Magento\\Framework\\App\\Request\\Http'); /* empty action */ $request->setRequestUri('core/index/index'); $this->assertInstanceOf('Magento\\Framework\\Controller\\ResultInterface', $this->_model->dispatch($request)); }
public function dispatch(\Magento\Framework\App\RequestInterface $request) { foreach ($this->_routerList as $router) { $this->_logger->addDebug(get_class($router)); } return parent::dispatch($request); }
public function testDispatchedNotFoundException() { $this->routerList->expects($this->any()) ->method('valid') ->will($this->returnValue(true)); $response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false); $controllerInstance = $this->getMock('Magento\Framework\App\ActionInterface'); $controllerInstance->expects($this->any()) ->method('execute') ->with($this->request) ->will($this->returnValue($response)); $this->router->expects($this->at(0)) ->method('match') ->with($this->request) ->willThrowException(new NotFoundException(new \Magento\Framework\Phrase('Page not found.'))); $this->router->expects($this->at(1)) ->method('match') ->with($this->request) ->will($this->returnValue($controllerInstance)); $this->routerList->expects($this->any()) ->method('current') ->will($this->returnValue($this->router)); $this->request->expects($this->at(0))->method('isDispatched')->will($this->returnValue(false)); $this->request->expects($this->at(1))->method('initForward'); $this->request->expects($this->at(2))->method('setActionName')->with('noroute'); $this->request->expects($this->at(3))->method('setDispatched')->with(false); $this->request->expects($this->at(4))->method('isDispatched')->will($this->returnValue(false)); $this->request->expects($this->at(5))->method('setDispatched')->with(true); $this->request->expects($this->at(6))->method('isDispatched')->will($this->returnValue(true)); $this->assertEquals($response, $this->model->dispatch($this->request)); }
/** * {@inheritdoc} */ public function dispatch(\Magento\Framework\App\RequestInterface $request) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'dispatch'); if (!$pluginInfo) { return parent::dispatch($request); } else { return $this->___callPlugins('dispatch', func_get_args(), $pluginInfo); } }
/** * @param string $mode * @param string $exceptionMessage * @param string $sessionMessage * @dataProvider dispatchedWithPhpExceptionDataProvider */ public function testDispatchedPhpException($mode, $exceptionMessage, $sessionMessage) { $this->routerList->expects($this->any())->method('valid')->willReturn(true); $this->resultRedirect = $this->getMock('Magento\\Framework\\Controller\\Result\\Redirect', [], [], '', false); $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false); $controllerInstance = $this->getMock('Magento\\Framework\\App\\ActionInterface'); $controllerInstance->expects($this->any())->method('getResponse')->willReturn($response); $controllerInstance->expects($this->any())->method('dispatch')->with($this->request)->willThrowException(new \Exception(new \Magento\Framework\Phrase($exceptionMessage))); $controllerInstance->expects($this->once())->method('getDefaultResult')->willReturn($this->resultRedirect); $this->router->expects($this->once())->method('match')->with($this->request)->willReturn($controllerInstance); $this->routerList->expects($this->any())->method('current')->willReturn($this->router); $this->request->expects($this->at(0))->method('isDispatched')->willReturn(false); $this->request->expects($this->once())->method('setDispatched')->with(true); $this->request->expects($this->at(2))->method('isDispatched')->willReturn(true); $this->appState->expects($this->once())->method('getMode')->willReturn($mode); $this->messageManager->expects($this->once())->method('addError')->with($sessionMessage); $this->logger->expects($this->once())->method('critical')->with($exceptionMessage); $this->assertEquals($this->resultRedirect, $this->model->dispatch($this->request)); }