Exemplo n.º 1
0
 public function addRouteCollection(RouteCollection $collection)
 {
     $routes = $collection->getRoutes();
     foreach ($routes as $route) {
         $this->routes[] = $route;
     }
 }
Exemplo n.º 2
0
 public function testMethods()
 {
     $callback = function () {
     };
     $path = "/foo";
     $baseRoute = new Route();
     $collection = new RouteCollection($baseRoute);
     $returns = [];
     $returns[] = $collection->get($path, $callback);
     $returns[] = $collection->post($path, $callback);
     $returns[] = $collection->put($path, $callback);
     $returns[] = $collection->delete($path, $callback);
     $returns[] = $collection->head($path, $callback);
     $returns[] = $collection->options($path, $callback);
     foreach ($returns as $return) {
         $this->assertInstanceOf(Route::class, $return);
     }
     $this->assertSame(Route::HTTP_GET, $returns[0]->getMethod());
     $this->assertSame(Route::HTTP_POST, $returns[1]->getMethod());
     $this->assertSame(Route::HTTP_PUT, $returns[2]->getMethod());
     $this->assertSame(Route::HTTP_DELETE, $returns[3]->getMethod());
     $this->assertSame(Route::HTTP_HEAD, $returns[4]->getMethod());
     $this->assertSame(Route::HTTP_OPTIONS, $returns[5]->getMethod());
     $routes = $collection->getRoutes();
     foreach ($routes as $route) {
         $this->assertSame($callback, $route->getCallback());
         $this->assertSame($path, $route->getPath());
         $this->assertSame([], $route->getBefore());
         $this->assertSame([], $route->getAfter());
     }
     // Change path and retest, all routes should be updated
     $path2 = "/bar";
     $collection->path($path2);
     foreach ($routes as $route) {
         $this->assertSame($path2, $route->getPath());
     }
 }