Пример #1
0
 public function testDynamicFilterMatch()
 {
     $collection = new RouteCollection();
     $route1 = new Route('/hello/{name}', ['_controller' => 'TastRouter\\Test\\controllers\\FooController::indexAction', 'methods' => 'GET', 'name' => '\\w+']);
     $route2 = new Route('/foo1/{foo1}/foo2/{foo2}', ['_controller' => 'TastRouter\\Test\\controllers\\FooController::indexAction', 'methods' => 'GET', 'foo1' => '\\w+', 'foo2' => '\\d+']);
     //        $collection->attachRoute($route1);
     $collection->attachRoute($route2);
     $router = new Router($collection);
     //        $route = $router->match('/hello/xujiajun','GET');
     //        $this->assertEquals($route->getParameterByName('name'),'xujiajun');
     $router->match('/foo1/foo1/foo2/123', 'GET');
     $this->assertEquals($route2->getParameterByName('foo1'), 'foo1');
     $this->assertEquals($route2->getParameterByName('foo2'), '123');
     //        $router->match('/foo1/foo1/foo2/fo2','GET');
 }
Пример #2
0
 public function testRouteConfig()
 {
     $file = __DIR__ . '/configs/test_routes.yml';
     $array = Yaml::parse(file_get_contents($file));
     $router = Router::parseConfig($array);
     $router->match("/hello/xujiajun", 'GET');
     $url = $router->generate('hello_show', ['xujiajun']);
     $this->assertEquals($url, '/hello/xujiajun');
 }
Пример #3
0
 /**
  * @expectedException     Exception
  */
 public function testFailGenerate()
 {
     list($route1, $route2, $route3, $route4) = $this->getRoutes();
     $collection = new RouteCollection();
     $collection->attachRoute($route2);
     $router = new Router($collection);
     $router->match("/foo1/xujiajun", 'GET');
     $url = $router->generate('say_hello', ['xujiajun']);
     $this->assertEquals($url, '/hello/xujiajun');
 }