コード例 #1
0
ファイル: Router.php プロジェクト: cicada/cicada
 public function addRouteCollection(RouteCollection $collection)
 {
     $routes = $collection->getRoutes();
     foreach ($routes as $route) {
         $this->routes[] = $route;
     }
 }
コード例 #2
0
ファイル: RouterTest.php プロジェクト: cicada/cicada
 public function testAddRoute()
 {
     // Create Router, add some Routes
     $router = new Router();
     $routes = [new Route('/foo'), new Route('/bar'), new Route('/baz')];
     foreach ($routes as $route) {
         $router->addRoute($route);
     }
     $this->assertSame($routes, $router->getRoutes());
     // Create a RouteCollection, add some Routes
     $col = new RouteCollection(new Route());
     $col->get('/x', function () {
     });
     $col->get('/y', function () {
     });
     $col->get('/z', function () {
     });
     // Add it to the router
     $router->addRouteCollection($col);
     $allRoutes = array_merge($routes, $col->getRoutes());
     $this->assertSame($allRoutes, $router->getRoutes());
     // Anything added to the collection after adding the collection to the
     // router should not be registered.
     $col->get('/a', function () {
     });
     $col->get('/b', function () {
     });
     $col->get('/c', function () {
     });
     $this->assertSame($allRoutes, $router->getRoutes());
 }
コード例 #3
0
ファイル: RouteCollectionTest.php プロジェクト: cicada/cicada
 /**
  * @expectedException BadMethodCallException
  * @expectedExceptionMessage Method foo does not exist.
  */
 public function testInvalidMethod()
 {
     $baseRoute = new Route();
     $collection = new RouteCollection($baseRoute);
     $collection->foo();
 }