public function testGetMatchedRoutes($table)
{
$this->assertEmpty($table->getMatchedRoutes(Request::METHOD_GET, '/nothing'));
//Existing routes
$res = $table->getMatchedRoutes(Request::METHOD_GET, '/api/users/v12/hotels');
$this->assertNotEmpty($res);
$this->assertEquals(1, count($res));
//Trailing slash should not be a trouble
$res = $table->getMatchedRoutes(Request::METHOD_GET, '/api/users/v12/hotels/');
$this->assertNotEmpty($res);
$this->assertEquals(1, count($res));
$route = current($res);
$this->assertInstanceOf('Scalr\\Api\\Rest\\Routing\\Route', $route);
$this->assertEquals(['apiversion' => 12], $route->getParams());
$res = $table->getMatchedRoutes(Request::METHOD_POST, '/api/users/v1/flights');
$this->assertNotEmpty($res);
$this->assertEquals(1, count($res));
$route = current($res);
$this->assertInstanceOf('Scalr\\Api\\Rest\\Routing\\Route', $route);
$this->assertEquals(['apiversion' => 1], $route->getParams());
//Missing method on existing route
$this->assertEmpty($table->getMatchedRoutes(Request::METHOD_GET, '/api/users/v1/flights'));
//Not complete path
$this->assertEmpty($table->getMatchedRoutes(Request::METHOD_POST, '/api/users/v1'));
//Two different routes on the same path with different methods
$getFlightsRoute = (new Route('/api/users/v:apiversion/flights', function () {
}, ['apiversion' => '[\\d]+']))->setMethods([Request::METHOD_GET]);
$table->appendRoute($getFlightsRoute);
$res = $table->getMatchedRoutes(Request::METHOD_GET, '/api/users/v1/flights');
$this->assertNotEmpty($res);
$this->assertEquals(1, count($res));
$route = current($res);
$this->assertSame($getFlightsRoute, $route);
//Two different routes on the same path with different requirements and handlers
$getFlightsRoute2 = (new Route('/api/users/v:apiversion/flights', function () {
}, ['apiversion' => '[\\w]+']))->setMethods([Request::METHOD_GET]);
$table->appendRoute($getFlightsRoute2);
//It matches the first
$res = $table->getMatchedRoutes(Request::METHOD_GET, '/api/users/v1/flights');
$this->assertEquals(1, count($res));
$this->assertSame($getFlightsRoute, $res[0]);
//It does not matches the first but matches the second
$res = $table->getMatchedRoutes(Request::METHOD_GET, '/api/users/version2/flights');
$this->assertEquals(1, count($res));
$this->assertSame($getFlightsRoute2, $res[0]);
//Two different routes on the same path with the same requirements, same methods but with different handlers
$getFlightsRoute3 = (new Route('/api/users/v:apiversion/flights', function () {
/* handler 2 */
}, ['apiversion' => '[\\w]+']))->setMethods([Request::METHOD_GET]);
$table->appendRoute($getFlightsRoute3);
$res = $table->getMatchedRoutes(Request::METHOD_GET, '/api/users/version2/flights');
$this->assertEquals(2, count($res));
$this->assertContains($getFlightsRoute2, $res);
$this->assertContains($getFlightsRoute3, $res);
}