Skip to content

Commit

Permalink
Merge pull request #110 from timplunkett/master
Browse files Browse the repository at this point in the history
[Routing] Use correct exception message in ChainRouter::match()
  • Loading branch information
lsmith77 committed Aug 26, 2014
2 parents fd2e124 + c151993 commit 286f7aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ChainRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,17 @@ private function doMatch($url, Request $request = null)
{
$methodNotAllowed = null;

$requestForMatching = $request;
foreach ($this->all() as $router) {
try {
// the request/url match logic is the same as in Symfony/Component/HttpKernel/EventListener/RouterListener.php
// matching requests is more powerful than matching URLs only, so try that first
if ($router instanceof RequestMatcherInterface) {
if (null === $request) {
$request = Request::create($url);
if (empty($requestForMatching)) {
$requestForMatching = Request::create($url);
}

return $router->matchRequest($request);
return $router->matchRequest($requestForMatching);
}
// every router implements the match method
return $router->match($url);
Expand Down
25 changes: 25 additions & 0 deletions Tests/Routing/ChainRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,31 @@ public function testMatchRequestNotFound()
$this->router->matchRequest(Request::create('/test'));
}

/**
* Call match on ChainRouter that has RequestMatcher in the chain.
*
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
* @expectedExceptionMessage None of the routers in the chain matched url '/test'
*/
public function testMatchWithRequestMatchersNotFound()
{
$url = '/test';
$request = Request::create('/test');

$high = $this->getMock('Symfony\Cmf\Component\Routing\Tests\Routing\RequestMatcher');

$high
->expects($this->once())
->method('matchRequest')
->with($request)
->will($this->throwException(new \Symfony\Component\Routing\Exception\ResourceNotFoundException))
;

$this->router->add($high, 20);

$this->router->match($url);
}

/**
* If any of the routers throws a not allowed exception and no other matches, we need to see this
*
Expand Down

0 comments on commit 286f7aa

Please sign in to comment.