/**
  * On request received event, configure the router.
  * 
  * @param  DidReceiveRequest $event Event triggered when a request was received.
  */
 public function onRequest(DidReceiveRequest $event)
 {
     $request = $event->getRequest();
     $protocol = $request->getScheme();
     $host = $request->getHost();
     $port = $request->getPort();
     if (!empty($protocol)) {
         $this->router->setProtocol($protocol);
     }
     if (!empty($host)) {
         $this->router->setHost($host);
     }
     if (!empty($port)) {
         $this->router->setPort($port);
     }
 }
 /**
  * @covers ::handleRequest
  */
 public function testHandlingRequest()
 {
     $this->application->addTestModule(new SplotResponseTestModule());
     $request = Request::create('/');
     $didReceiveRequestCalled = false;
     $didFindRouteForRequestCalled = false;
     $eventManager = $this->application->getContainer()->get('event_manager');
     $eventManager->subscribe(DidReceiveRequest::getName(), function () use(&$didReceiveRequestCalled) {
         $didReceiveRequestCalled = true;
     });
     $eventManager->subscribe(DidFindRouteForRequest::getName(), function () use(&$didFindRouteForRequestCalled) {
         $didFindRouteForRequestCalled = true;
     });
     $response = $this->application->handleRequest($request);
     $this->assertSame($request, $this->application->getContainer()->get('request'));
     $this->assertTrue($response instanceof Response);
     $this->assertEquals('INDEX', $response->getContent());
     $this->assertTrue($didReceiveRequestCalled);
 }
Пример #3
0
 /**
  * @covers \Splot\Framework\Events\DidReceiveRequest::__construct
  * @covers \Splot\Framework\Events\DidReceiveRequest::getRequest
  */
 public function testDidReceiveRequest()
 {
     $request = Request::create('/test/');
     $event = new Events\DidReceiveRequest($request);
     $this->assertSame($request, $event->getRequest());
 }