コード例 #1
0
ファイル: RouterTest.php プロジェクト: roydejong/Enlighten
 public function testCreateRedirect()
 {
     // Prepare: Prepare environment to capture response
     $response = new Response();
     $request = new Request();
     $request->setRequestUri('/redirect/bla');
     $context = new Context();
     $context->registerInstance($response);
     $context->registerInstance($request);
     $router = new Router();
     $router->setContext($context);
     $route = $router->createRedirect('/redirect/$testVar', '/target/$testVar', true);
     $this->assertEquals('/redirect/$testVar', $route->getPattern());
     $routeResult = $router->route($request);
     $this->assertEquals($route, $routeResult);
     $router->dispatch($routeResult, $request);
     $this->assertEquals(ResponseCode::HTTP_MOVED_PERMANENTLY, $response->getResponseCode());
     $this->assertEquals('/target/bla', $response->getHeader('Location'));
 }
コード例 #2
0
ファイル: Enlighten.php プロジェクト: roydejong/Enlighten
 /**
  * Marks the application as being in a subdirectory. This affects how routes are matched.
  *
  * For example, if you set "/projects/one" as your subdirectory, the router will assume that all routes begin with
  * that value. A route for "/test.html" will then match against requests for "/projects/one/test.html".
  *
  * NB: You should not use a trailing slash in your subdirectory names.
  *
  * @param string $subdirectory
  * @return $this
  */
 public function setSubdirectory($subdirectory)
 {
     $this->bootstrapRouter();
     $this->router->setSubdirectory($subdirectory);
     return $this;
 }
コード例 #3
0
ファイル: EnlightenTest.php プロジェクト: roydejong/Enlighten
 /**
  * @runInSeparateProcess
  */
 public function testCustomOptionsResponse()
 {
     $router = new Router();
     $unrestrictedRoute = new Route('/sample', function (Request $request) {
         echo 'hello ' . $request->getMethod() . '!';
     });
     $router->register($unrestrictedRoute);
     $app = new Enlighten();
     $app->setRouter($router);
     $optionsRequest = new Request();
     $optionsRequest->setRequestUri('/sample');
     $optionsRequest->setMethod(RequestMethod::OPTIONS);
     $app->setRequest($optionsRequest);
     $response = $app->start();
     $this->assertEquals('hello OPTIONS!', $response->getBody());
     $this->assertEquals(ResponseCode::HTTP_OK, $response->getResponseCode());
 }