Ejemplo n.º 1
0
 public function testGetSetSubdirectory()
 {
     $router = new Router();
     $route = new Route('/bla.html', null);
     $router->register($route);
     $this->assertNull($router->getSubdirectory(), 'Default should be null');
     $this->assertEquals($router, $router->setSubdirectory('/my/dir'), 'Fluent API return');
     $this->assertEquals('/my/dir', $router->getSubdirectory());
     $this->assertEquals($router->getSubdirectory(), '/my/dir', 'Routes should inherit subdirectory setting');
 }
Ejemplo n.º 2
0
 /**
  * Internal function to register a new route.
  * Will bootstrap the router if necessary.
  *
  * @param string $pattern The regex pattern to match requests against (supports dynamic variables).
  * @param mixed|string $target The target function or path for the route.
  * @param array $requestMethods A list of acceptable request methods, leave empty to disable constraint.
  * @return Route The generated route.
  */
 private function registerRoute($pattern, $target, array $requestMethods = [])
 {
     $this->bootstrapRouter();
     $route = new Route($pattern, $target);
     if (!empty($requestMethods)) {
         $route->setAcceptableMethods($requestMethods);
     }
     $this->router->register($route);
     return $route;
 }
Ejemplo n.º 3
0
 /**
  * @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());
 }