22
22
23
23
class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
24
24
{
25
- /**
26
- * @dataProvider provider
27
- */
28
- public function testCollect (Request $ request , Response $ response )
25
+ public function testCollect ()
29
26
{
30
27
$ c = new RequestDataCollector ();
31
28
32
- $ c ->collect ($ request , $ response );
29
+ $ c ->collect ($ this ->createRequest (), $ this ->createResponse ());
30
+
<
10000
/td>31
+ $ attributes = $ c ->getRequestAttributes ();
33
32
34
33
$ this ->assertSame ('request ' , $ c ->getName ());
35
34
$ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\HeaderBag ' , $ c ->getRequestHeaders ());
36
35
$ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\ParameterBag ' , $ c ->getRequestServer ());
37
36
$ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\ParameterBag ' , $ c ->getRequestCookies ());
38
- $ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\ParameterBag ' , $ c -> getRequestAttributes () );
37
+ $ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\ParameterBag ' , $ attributes );
39
38
$ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\ParameterBag ' , $ c ->getRequestRequest ());
40
39
$ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\ParameterBag ' , $ c ->getRequestQuery ());
41
40
$ this ->assertSame ('html ' , $ c ->getFormat ());
42
41
$ this ->assertSame ('foobar ' , $ c ->getRoute ());
43
42
$ this ->assertSame (array ('name ' => 'foo ' ), $ c ->getRouteParams ());
44
43
$ this ->assertSame (array (), $ c ->getSessionAttributes ());
45
44
$ this ->assertSame ('en ' , $ c ->getLocale ());
45
+ $ this ->assertSame ('Resource(stream) ' , $ attributes ->get ('resource ' ));
46
+ $ this ->assertSame ('Object(stdClass) ' , $ attributes ->get ('object ' ));
46
47
47
48
$ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\HeaderBag ' , $ c ->getResponseHeaders ());
48
49
$ this ->assertSame ('OK ' , $ c ->getStatusText ());
@@ -52,10 +53,8 @@ public function testCollect(Request $request, Response $response)
52
53
53
54
/**
54
55
* Test various types of controller callables.
55
- *
56
- * @dataProvider provider
57
56
*/
58
- public function testControllerInspection (Request $ request , Response $ response )
57
+ public function testControllerInspection ()
59
58
{
60
59
// make sure we always match the line number
61
60
$ r1 = new \ReflectionMethod ($ this , 'testControllerInspection ' );
@@ -136,35 +135,37 @@ function () { return 'foo'; },
136
135
);
137
136
138
137
$ c = new RequestDataCollector ();
139
-
138
+ $ request = $ this ->createRequest ();
139
+ $ response = $ this ->createResponse ();
140
140
foreach ($ controllerTests as $ controllerTest ) {
141
141
$ this ->injectController ($ c , $ controllerTest [1 ], $ request );
142
142
$ c ->collect ($ request , $ response );
143
143
$ this ->assertSame ($ controllerTest [2 ], $ c ->getController (), sprintf ('Testing: %s ' , $ controllerTest [0 ]));
144
144
}
145
145
}
146
146
147
- public function provider ()
147
+ protected function createRequest ()
148
148
{
149
- if (!class_exists ('Symfony\Component\HttpFoundation\Request ' )) {
150
- return array (array (null , null ));
151
- }
152
-
153
149
$ request = Request::create ('http://test.com/foo?bar=baz ' );
154
150
$ request ->attributes ->set ('foo ' , 'bar ' );
155
151
$ request ->attributes ->set ('_route ' , 'foobar ' );
156
152
$ request ->attributes ->set ('_route_params ' , array ('name ' => 'foo ' ));
153
+ $ request ->attributes ->set ('resource ' , fopen (__FILE__ , 'r ' ));
154
+ $ request ->attributes ->set ('object ' , new \stdClass ());
155
+
156
+ return $ request ;
157
+ }
157
158
159
+ protected function createResponse ()
160
+ {
158
161
$ response = new Response ();
159
162
$ response ->setStatusCode (200 );
160
163
$ response ->headers ->set ('Content-Type ' , 'application/json ' );
161
164
$ response ->headers ->setCookie (new Cookie ('foo ' ,'bar ' ,1 ,'/foo ' ,'localhost ' ,true ,true ));
162
165
$ response ->headers ->setCookie (new Cookie ('bar ' ,'foo ' ,new \DateTime ('@946684800 ' )));
163
166
$ response ->headers ->setCookie (new Cookie ('bazz ' ,'foo ' ,'2000-12-12 ' ));
164
167
165
- return array (
166
- array ($ request , $ response )
167
- );
168
+ return $ response ;
168
169
}
169
170
170
171
/**
0 commit comments