14
14
use Symfony \Component \Routing \Exception \MethodNotAllowedException ;
15
15
use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
16
16
use Symfony \Component \Routing \Exception \RouteNotFoundException ;
17
+ use Symfony \Component \Routing \RequestContext ;
17
18
use Symfony \Component \Routing \RouteCollection ;
18
19
use Symfony \Component \HttpFoundation \Request ;
19
20
20
21
use Symfony \Cmf \Component \Routing \ChainRouter ;
21
22
use Symfony \Cmf \Component \Routing \Test \CmfUnitTestCase ;
23
+ use Symfony \Component \Routing \RouterInterface ;
22
24
23
25
class ChainRouterTest extends CmfUnitTestCase
24
26
{
27
+ /**
28
+ * @var ChainRouter
29
+ */
30
+ private $ router ;
31
+ /**
32
+ * @var RequestContext|\PHPUnit_Framework_MockObject_MockObject
33
+ */
34
+ private $ context ;
35
+
25
36
public function setUp ()
26
37
{
27
38
$ this ->router = new ChainRouter ($ this ->getMock ('Psr\Log\LoggerInterface ' ));
@@ -54,6 +65,7 @@ public function testSortRouters()
54
65
{
55
66
list ($ low , $ medium , $ high ) = $ this ->createRouterMocks ();
56
67
// 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 */
57
69
$ router = $ this ->buildMock ('Symfony\Cmf\Component\Routing\ChainRouter ' , array ('sortRouters ' ));
58
70
$ router
59
71
->expects ($ this ->once ())
@@ -87,6 +99,7 @@ public function testReSortRouters()
87
99
list ($ low , $ medium , $ high ) = $ this ->createRouterMocks ();
88
100
$ highest = clone $ high ;
89
101
// 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 */
90
103
$ router = $ this ->buildMock ('Symfony\Cmf\Component\Routing\ChainRouter ' , array ('sortRouters ' ));
91
104
$ router
92
105
->expects ($ this ->at (0 ))
@@ -253,7 +266,6 @@ public function testMatchRequest()
253
266
public function testMatchWithRequestMatchers ()
254
267
{
255
268
$ url = '/test ' ;
256
- $ request = Request::create ('/test ' );
257
269
258
270
list ($ low ) = $ this ->createRouterMocks ();
259
271
@@ -262,7 +274,9 @@ public function testMatchWithRequestMatchers()
262
274
$ high
263
275
->expects ($ this ->once ())
264
276
->method ('matchRequest ' )
265
- ->with ($ request )
277
+ ->with ($ this ->callback (function (Request $ r ) use ($ url ) {
278
+ return $ r ->getPathInfo () === $ url ;
279
+ }))
266
280
->will ($ this ->throwException (new \Symfony \Component \Routing \Exception \ResourceNotFoundException ))
267
281
;
268
282
$ low
@@ -687,6 +701,9 @@ public function testSupport()
687
701
$ this ->router ->generate ('foobar ' );
688
702
}
689
703
704
+ /**
705
+ * @return RouterInterface[]|\PHPUnit_Framework_MockObject_MockObject[]
706
+ */
690
707
protected function createRouterMocks ()
691
708
{
692
709
return array (
0 commit comments