/** * Test l'ajout et l'itération */ public function testGlobal() { $routes = new Routes(); $routeNews = new Route('/news', 'NewsController@index'); $routeUser = new Route('/users', 'UsersController@index'); $this->assertCount(0, $routes->routes); $routes->add($routeNews); $this->assertCount(1, $routes->routes); $routes->add($routeUser); $this->assertCount(2, $routes->routes); $routes->rewind(); $i = 0; while ($routes->valid()) { $route = $routes->current(); $key = $routes->key(); $this->assertEquals($i, $key); $this->assertInstanceOf(Route::class, $route); $i += 1; $routes->next(); } $this->assertNull($routes->current()); }
/** * Ajoute plusieurs routes à la même méthode * * @param array $methods * @param string $path * @param string|callable $callable * @param array $with * @return Routes */ public function match(array $methods, $path, $callable, array $with = []) { if (empty($methods)) { throw new InvalidArgumentException('No methods pass on this function'); } $routes = new Routes(); foreach ($methods as $method) { $route = $this->callMethod($method, $path, $callable); if ($route) { $this->addWiths($route, $with); $routes->add($route); } } return $routes; }