public function testNestedRouteCollection()
 {
     $collection = new RouteCollection();
     $collection->add('home', new Route('/'));
     $collection2 = new RouteCollection('/admin');
     $collection2->add('dashboard', new Route('/dashboard'));
     $collection3 = new RouteCollection('/dashboard');
     $collection3->add('dashboard-monitoring', (new Route('/monitoring'))->secureOnly());
     $collection2->addCollection($collection3);
     $collection->addCollection($collection2);
     $this->assertArrayHasKey('dashboard', $collection->all());
     $this->assertTrue($collection->get('dashboard')->getPath() === '/admin/dashboard');
     $this->assertTrue($collection->get('dashboard-monitoring')->getPath() === '/admin/dashboard/monitoring');
     $this->assertTrue($collection->get('dashboard-monitoring')->getSchema()->has('http') === false);
     $this->assertTrue($collection->get('dashboard-monitoring')->getSchema()->has('https'));
 }
 public function testBasicRouteRegex()
 {
     $collection = new RouteCollection();
     $collection->add('category', new Route('/category/{name}'));
     $collection->add('page', Route::create('/page/{page}.{ext}')->setRequirement('ext', 'htm|html')->setRequirement('page', '[a-z]+'));
     $collection->add('profile', Route::create('/profile/{username}')->setDefault('username', 'me'));
     $collection->add('read', RouteFactory::createHttpGet('/read/{slug}')->setRequirement('slug', '[a-z\\-]+'));
     $this->assertTrue((bool) preg_match($collection->get('category')->getRegex()->getRegexPattern(), '/category/music'));
     $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index.html'));
     $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index.htm'));
     $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index05.html') === false);
     $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index.php') === false);
     $this->assertTrue((bool) preg_match($collection->get('profile')->getRegex()->getRegexPattern(), '/profile') === true);
     $this->assertTrue((bool) preg_match($collection->get('profile')->getRegex()->getRegexPattern(), '/profile/danu') === true);
     $this->assertTrue((bool) preg_match($collection->get('read')->getRegex()->getRegexPattern(), '/read/welcome-to-the-jungle') === true);
     $this->assertTrue((bool) preg_match($collection->get('read')->getRegex()->getRegexPattern(), '/read/WELCOME-TO-THE') === false);
 }
 /**
  * Generate route request by route name.
  *
  * @param string $name
  * @param array  $parameters
  *
  * @return RequestContext
  */
 public function generateRoute($name, array $parameters = array())
 {
     $route = $this->collection->get($name);
     if (null === $route) {
         throw new InvalidArgumentException(sprintf('Route with name "%s" not found.', $name));
     }
     $request = RequestContext::createFromRoute($route, $parameters);
     if (false === $this->isMatch($route, $request)) {
         throw new InvalidArgumentException(sprintf('Failed generate route with name "%s", mismatch rules.', $name));
     }
     return $request;
 }