1
1
<?php
2
2
3
- namespace Symfony \Cmf \Bundle \RoutingBundle \Tests \Routing ;
3
+ namespace Symfony \Cmf \Bundle \RoutingBundle \Tests \Unit \ Routing ;
4
4
5
+ use Symfony \Cmf \Component \Routing \Event \Events ;
6
+ use Symfony \Cmf \Component \Routing \Event \RouterMatchEvent ;
5
7
use Symfony \Component \DependencyInjection \ContainerInterface ;
8
+ use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
6
9
use Symfony \Component \HttpFoundation \Request ;
7
10
8
11
use Symfony \Cmf \Component \Routing \RouteObjectInterface ;
@@ -20,6 +23,8 @@ class DynamicRouterTest extends CmfUnitTestCase
20
23
protected $ context ;
21
24
/** @var Request */
22
25
protected $ request ;
26
+ /** @var EventDispatcherInterface */
27
+ protected $ eventDispatcher ;
23
28
protected $ container ;
24
29
25
30
public function setUp ()
@@ -36,8 +41,8 @@ public function setUp()
36
41
$ this ->request = Request::create ('/foo ' );
37
42
$ this ->container = $ this ->buildMock ('Symfony \\Component \\DependencyInjection \\ContainerInterface ' );
38
43
$ this ->context = $ this ->buildMock ('Symfony \\Component \\Routing \\RequestContext ' );
39
-
40
- $ this ->router = new DynamicRouter ($ this ->context , $ this ->matcher , $ this ->generator );
44
+ $ this -> eventDispatcher = $ this -> buildMock ( ' Symfony\Component\EventDispatcher\EventDispatcherInterface ' );
45
+ $ this ->router = new DynamicRouter ($ this ->context , $ this ->matcher , $ this ->generator , '' , $ this -> eventDispatcher );
41
46
$ this ->router ->setContainer ($ this ->container );
42
47
}
43
48
@@ -57,6 +62,11 @@ public function testMatch()
57
62
->will ($ this ->returnValue ($ this ->request ))
58
63
;
59
64
65
+ $ this ->eventDispatcher ->expects ($ this ->once ())
66
+ ->method ('dispatch ' )
67
+ ->with (Events::PRE_DYNAMIC_MATCH , $ this ->equalTo (new RouterMatchEvent ()))
68
+ ;
69
+
60
70
$ parameters = $ this ->router ->match ('/foo ' );
61
71
$ this ->assertEquals (array ('foo ' => 'bar ' ), $ parameters );
62
72
@@ -65,10 +75,9 @@ public function testMatch()
65
75
66
76
public function testMatchRequest ()
67
77
{
68
- $ this ->container ->expects ($ this ->once ())
69
- ->method ('get ' )
70
- ->with ('request ' )
71
- ->will ($ this ->returnValue ($ this ->request ))
78
+ $ this ->eventDispatcher ->expects ($ this ->once ())
79
+ ->method ('dispatch ' )
80
+ ->with (Events::PRE_DYNAMIC_MATCH_REQUEST , $ this ->equalTo (new RouterMatchEvent ($ this ->request )))
72
81
;
73
82
74
83
$ parameters = $ this ->router ->matchRequest ($ this ->request );
@@ -88,6 +97,22 @@ public function testMatchNoRequest()
88
97
->will ($ this ->returnValue (null ))
89
98
;
90
99
100
+ $ this ->eventDispatcher ->expects ($ this ->once ())
101
+ ->method ('dispatch ' )
102
+ ->with (Events::PRE_DYNAMIC_MATCH , $ this ->equalTo (new RouterMatchEvent ()))
103
+ ;
104
+
91
105
$ this ->router ->match ('/foo ' );
92
106
}
107
+
108
+ public function testEventOptional ()
109
+ {
110
+ $ router = new DynamicRouter ($ this ->context , $ this ->matcher , $ this ->generator );
111
+
112
+ $ parameters = $ router ->matchRequest ($ this ->request );
113
+ $ this ->assertEquals (array ('foo ' => 'bar ' ), $ parameters );
114
+
115
+ $ this ->assertRequestAttributes ($ this ->request );
116
+ }
117
+
93
118
}
0 commit comments