Skip to content

Commit 286f7aa

Browse files
committed
Merge pull request #110 from timplunkett/master
[Routing] Use correct exception message in ChainRouter::match()
2 parents fd2e124 + c151993 commit 286f7aa

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

ChainRouter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,17 @@ private function doMatch($url, Request $request = null)
164164
{
165165
$methodNotAllowed = null;
166166

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

176-
return $router->matchRequest($request);
177+
return $router->matchRequest($requestForMatching);
177178
}
178179
// every router implements the match method
179180
return $router->match($url);

Tests/Routing/ChainRouterTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,31 @@ public function testMatchRequestNotFound()
385385
$this->router->matchRequest(Request::create('/test'));
386386
}
387387

388+
/**
389+
* Call match on ChainRouter that has RequestMatcher in the chain.
390+
*
391+
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
392+
* @expectedExceptionMessage None of the routers in the chain matched url '/test'
393+
*/
394+
public function testMatchWithRequestMatchersNotFound()
395+
{
396+
$url = '/test';
397+
$request = Request::create('/test');
398+
399+
$high = $this->getMock('Symfony\Cmf\Component\Routing\Tests\Routing\RequestMatcher');
400+
401+
$high
402+
->expects($this->once())
403+
->method('matchRequest')
404+
->with($request)
405+
->will($this->throwException(new \Symfony\Component\Routing\Exception\ResourceNotFoundException))
406+
;
407+
408+
$this->router->add($high, 20);
409+
410+
$this->router->match($url);
411+
}
412+
388413
/**
389414
* If any of the routers throws a not allowed exception and no other matches, we need to see this
390415
*

0 commit comments

Comments
 (0)