Skip to content

Commit 6e69a35

Browse files
committed
Allow ChainRouter::match() to use the correct exception message when a RequestMatcherInterface router is used.
1 parent fd2e124 commit 6e69a35

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

ChainRouter.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,13 @@ private function doMatch($url, Request $request = null)
170170
// matching requests is more powerful than matching URLs only, so try that first
171171
if ($router instanceof RequestMatcherInterface) {
172172
if (null === $request) {
173-
$request = Request::create($url);
173+
$request_for_matching = Request::create($url);
174+
}
175+
else {
176+
$request_for_matching = $request;
174177
}
175178

176-
return $router->matchRequest($request);
179+
return $router->matchRequest($request_for_matching);
177180
}
178181
// every router implements the match method
179182
return $router->match($url);

Tests/Routing/ChainRouterTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,32 @@ 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+
$result = $this->router->match($url);
411+
$this->assertEquals(array('test'), $result);
412+
}
413+
388414
/**
389415
* If any of the routers throws a not allowed exception and no other matches, we need to see this
390416
*

0 commit comments

Comments
 (0)