Skip to content

Commit db8acd6

Browse files
committed
avoid random test failure when comparing requests that could be created at different timestamps
1 parent 4f160e2 commit db8acd6

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Tests/Routing/ChainRouterTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,25 @@
1414
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
1515
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
1616
use Symfony\Component\Routing\Exception\RouteNotFoundException;
17+
use Symfony\Component\Routing\RequestContext;
1718
use Symfony\Component\Routing\RouteCollection;
1819
use Symfony\Component\HttpFoundation\Request;
1920

2021
use Symfony\Cmf\Component\Routing\ChainRouter;
2122
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
23+
use Symfony\Component\Routing\RouterInterface;
2224

2325
class ChainRouterTest extends CmfUnitTestCase
2426
{
27+
/**
28+
* @var ChainRouter
29+
*/
30+
private $router;
31+
/**
32+
* @var RequestContext|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $context;
35+
2536
public function setUp()
2637
{
2738
$this->router = new ChainRouter($this->getMock('Psr\Log\LoggerInterface'));
@@ -54,6 +65,7 @@ public function testSortRouters()
5465
{
5566
list($low, $medium, $high) = $this->createRouterMocks();
5667
// We're using a mock here and not $this->router because we need to ensure that the sorting operation is done only once.
68+
/** @var $router ChainRouter|\PHPUnit_Framework_MockObject_MockObject */
5769
$router = $this->buildMock('Symfony\Cmf\Component\Routing\ChainRouter', array('sortRouters'));
5870
$router
5971
->expects($this->once())
@@ -87,6 +99,7 @@ public function testReSortRouters()
8799
list($low, $medium, $high) = $this->createRouterMocks();
88100
$highest = clone $high;
89101
// We're using a mock here and not $this->router because we need to ensure that the sorting operation is done only once.
102+
/** @var $router ChainRouter|\PHPUnit_Framework_MockObject_MockObject */
90103
$router = $this->buildMock('Symfony\Cmf\Component\Routing\ChainRouter', array('sortRouters'));
91104
$router
92105
->expects($this->at(0))
@@ -253,7 +266,6 @@ public function testMatchRequest()
253266
public function testMatchWithRequestMatchers()
254267
{
255268
$url = '/test';
256-
$request = Request::create('/test');
257269

258270
list($low) = $this->createRouterMocks();
259271

@@ -262,7 +274,9 @@ public function testMatchWithRequestMatchers()
262274
$high
263275
->expects($this->once())
264276
->method('matchRequest')
265-
->with($request)
277+
->with($this->callback(function (Request $r) use ($url) {
278+
return $r->getPathInfo() === $url;
279+
}))
266280
->will($this->throwException(new \Symfony\Component\Routing\Exception\ResourceNotFoundException))
267281
;
268282
$low
@@ -687,6 +701,9 @@ public function testSupport()
687701
$this->router->generate('foobar');
688702
}
689703

704+
/**
705+
* @return RouterInterface[]|\PHPUnit_Framework_MockObject_MockObject[]
706+
*/
690707
protected function createRouterMocks()
691708
{
692709
return array(

0 commit comments

Comments
 (0)