Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Routing] Use correct exception message in ChainRouter::match() #110

Merged
merged 4 commits into from
Aug 26, 2014
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions ChainRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,12 @@ private function doMatch($url, Request $request = null)
// matching requests is more powerful than matching URLs only, so try that first
if ($router instanceof RequestMatcherInterface) {
if (null === $request) {
$request = Request::create($url);
$requestForMatching = Request::create($url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about then:
move $requestForMatching = $request; to before the loop and then inside the loop do

if (empty(requestForMatching)) {
    $requestForMatching = Request::create($url);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, done.

} else {
$requestForMatching = $request;
}

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