fakeRequestValidator) { $this->fakeRequestValidator = new class implements ValidatorInterface { /** * @var bool */ public $valid; /** * @inheritDoc */ public function validate( RequestInterface $request, ActionInterface $action ): void { if (!$this->valid) { throw new InvalidRequestException(new NotFoundException(new Phrase('Not found'))); } } }; } return $this->fakeRequestValidator; } /** * @inheritDoc */ protected function setUp() { $this->_objectManager = Bootstrap::getObjectManager(); $this->_model = $this->_objectManager->create( FrontController::class, ['requestValidator' => $this->createRequestValidator()] ); } /** * Test dispatching an empty action. */ public function testDispatch() { if (!Bootstrap::canTestHeaders()) { $this->markTestSkipped('Can\'t test dispatch process without sending headers'); } $this->fakeRequestValidator->valid = true; $_SERVER['HTTP_HOST'] = 'localhost'; $this->_objectManager->get(State::class)->setAreaCode('frontend'); $request = $this->_objectManager->get(HttpRequest::class); /* empty action */ $request->setRequestUri('core/index/index'); $this->assertInstanceOf( ResultInterface::class, $this->_model->dispatch($request) ); } /** * Test request validator invalidating given request. */ public function testInvalidRequest() { if (!Bootstrap::canTestHeaders()) { $this->markTestSkipped('Can\'t test dispatch process without sending headers'); } $this->fakeRequestValidator->valid = false; $_SERVER['HTTP_HOST'] = 'localhost'; $this->_objectManager->get(State::class)->setAreaCode('frontend'); $request = $this->_objectManager->get(HttpRequest::class); /* empty action */ $request->setRequestUri('core/index/index'); $this->assertInstanceOf( ResultInterface::class, $this->_model->dispatch($request) ); } }