Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Routing] Fix router matching pattern against multiple hosts
  • Loading branch information
karolsojko committed Dec 14, 2013
1 parent cbce472 commit f727b22
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Expand Up @@ -75,7 +75,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
$this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);

return true;
continue;
}

// check HTTP method requirement
Expand Down
Expand Up @@ -54,6 +54,37 @@ public function test()
$this->assertEquals(array(0, 1, 2), $this->getLevels($traces));
}

public function testMatchRouteOnMultipleHosts()
{
$routes = new RouteCollection();
$routes->add('first', new Route(
'/mypath/',
array('_controller' => 'MainBundle:Info:first'),
array(),
array(),
'some.example.com'
));

$routes->add('second', new Route(
'/mypath/',
array('_controller' => 'MainBundle:Info:second'),
array(),
array(),
'another.example.com'
));

$context = new RequestContext();
$context->setHost('baz');

$matcher = new TraceableUrlMatcher($routes, $context);

$traces = $matcher->getTraces('/mypath/');
$this->assertEquals(
array(TraceableUrlMatcher::ROUTE_ALMOST_MATCHES, TraceableUrlMatcher::ROUTE_ALMOST_MATCHES),
$this->getLevels($traces)
);
}

public function getLevels($traces)
{
$levels = array();
Expand Down

0 comments on commit f727b22

Please sign in to comment.