public function testPriority() { $this->routes->add('default', new Route('/blog/', $this->endPoint), 70); $this->routes->add('cats', new Route('/cats/', $this->endPoint), 50); $this->routes->add('profile', new Route('/cats/', $this->endPoint), 60); $routes = $this->routes->getRoutes(); self::assertEquals(['default', 'profile', 'cats'], array_keys($routes)); }
protected function setUp() { $this->coll = new CollectionRoute(); $this->coll->add('main', new Route('/', function () { return 'main'; })); $this->coll->add('blog', new Route('/blog/{id}/', function () { return 'blog'; })); $this->matcher = new Matcher(new RouteService()); }
public function testMiddleware() { $route = new Route('/profile/{name}/', function ($name) { return $name; }); $route->pushMiddleware(new CallWithMatchParams()); $coll = new CollectionRoute(); $coll->add('profile', $route); $path = '/profile/alex/'; $matcher = new Matcher(new RouteService()); $activeRoute = $matcher->match($coll, $path)->current(); self::assertEquals('alex', $activeRoute(new Request($path))); }