/** * Route should set name and be cached by Router */ public function testRouteSetsNameAndIsCached() { $router = new RouterMock(); $route = new Route('/foo/bar', function () { }); $route->setRouter($router); $route->name('foo'); $cacheKeys = array_keys($router->cache); $cacheValues = array_values($router->cache); $this->assertEquals($cacheKeys[0], 'foo'); $this->assertSame($cacheValues[0], $route); }
/** * Map a route to a callback function * * @param string $pattern The URL pattern (ie. "/books/:id") * @param mixed $callable Anything that returns TRUE for is_callable() * @param string $method The HTTP request method (GET, POST, PUT, DELETE) * @return Route */ public function map($pattern, $callable, $method) { $route = new Route($pattern, $callable); $route->setRouter($this); $this->routes[$method][] = $route; return $route; }