public function testCanRetrieveCallback() { $callback = function () { return 'Hello, World!'; }; $route = new Route('test.route', '/', $callback); $this->assertSame($callback, $route->getCallback()); }
public function testRouteAttributesArePopulatedWithValues() { $route = new Route('test.route', '/api/:version/users/:id', function () { }); $matcher = new Matcher(new Collection([$route])); $request = $this->getRequestWithPath('/api/v3/users/65535'); $matcher->match($request); $this->assertEquals(['version' => 'v3', 'id' => '65535'], $route->getAttributes()); }
/** * Checks if the incoming request method matches against the * allowed methods in the `Route` object. * * @param ServerRequestInterface $request The incoming request. * @param Route $route The Route to match against. * @return boolean `true` if method matched, `false` otherwise. */ public function __invoke(ServerRequestInterface $request, Route $route) { return in_array($request->getMethod(), $route->getMethods()); }