31
31
use Symfony \Component \HttpKernel \Event \ResponseEvent ;
32
32
use Symfony \Component \HttpKernel \HttpKernel ;
33
33
use Symfony \Component \HttpKernel \HttpKernelInterface ;
34
+ use Symfony \Component \HttpKernel \Tests \Fixtures \DataCollector \DummyController ;
34
35
35
36
class RequestDataCollectorTest extends TestCase
36
37
{
@@ -91,22 +92,24 @@ public function testControllerInspection($name, $callable, $expected)
91
92
$ this ->assertSame ($ expected , $ c ->getController ()->getValue (true ), sprintf ('Testing: %s ' , $ name ));
92
93
}
93
94
94
- public function provideControllerCallables ()
95
+ public static function provideControllerCallables (): array
95
96
{
96
97
// make sure we always match the line number
97
- $ r1 = new \ReflectionMethod ($ this , 'testControllerInspection ' );
98
- $ r2 = new \ReflectionMethod ($ this , 'staticControllerMethod ' );
99
- $ r3 = new \ReflectionClass ($ this );
98
+ $ controller = new DummyController ();
99
+
100
+ $ r1 = new \ReflectionMethod ($ controller , 'regularCallable ' );
101
+ $ r2 = new \ReflectionMethod ($ controller , 'staticControllerMethod ' );
102
+ $ r3 = new \ReflectionClass ($ controller );
100
103
101
104
// test name, callable, expected
102
105
return [
103
106
[
104
107
'"Regular" callable ' ,
105
- [$ this , 'testControllerInspection ' ],
108
+ [$ controller , 'regularCallable ' ],
106
109
[
107
- 'class ' => self ::class,
108
- 'method ' => 'testControllerInspection ' ,
109
- 'file ' => __FILE__ ,
110
+ 'class ' => DummyController ::class,
111
+ 'method ' => 'regularCallable ' ,
112
+ 'file ' => $ r3 -> getFileName () ,
110
113
'line ' => $ r1 ->getStartLine (),
111
114
],
112
115
],
@@ -124,42 +127,42 @@ function () { return 'foo'; },
124
127
125
128
[
126
129
'Static callback as string ' ,
127
- __NAMESPACE__ . ' \RequestDataCollectorTest ::staticControllerMethod ' ,
130
+ DummyController::class. ' ::staticControllerMethod ' ,
128
131
[
129
- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
132
+ 'class ' => DummyController::class ,
130
133
'method ' => 'staticControllerMethod ' ,
131
- 'file ' => __FILE__ ,
134
+ 'file ' => $ r3 -> getFileName () ,
132
135
'line ' => $ r2 ->getStartLine (),
133
136
],
134
137
],
135
138
136
139
[
137
140
'Static callable with instance ' ,
138
- [$ this , 'staticControllerMethod ' ],
141
+ [$ controller , 'staticControllerMethod ' ],
139
142
[
140
- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
143
+ 'class ' => DummyController::class ,
141
144
'method ' => 'staticControllerMethod ' ,
142
- 'file ' => __FILE__ ,
145
+ 'file ' => $ r3 -> getFileName () ,
143
146
'line ' => $ r2 ->getStartLine (),
144
147
],
145
148
],
146
149
147
150
[
148
151
'Static callable with class name ' ,
149
- [' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' , 'staticControllerMethod ' ],
152
+ [DummyController::class , 'staticControllerMethod ' ],
150
153
[
151
- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
154
+ 'class ' => DummyController::class ,
152
155
'method ' => 'staticControllerMethod ' ,
153
- 'file ' => __FILE__ ,
156
+ 'file ' => $ r3 -> getFileName () ,
154
157
'line ' => $ r2 ->getStartLine (),
155
158
],
156
159
],
157
160
158
161
[
159
162
'Callable with instance depending on __call() ' ,
160
- [$ this , 'magicMethod ' ],
163
+ [$ controller , 'magicMethod ' ],
161
164
[
162
- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
165
+ 'class ' => DummyController::class ,
163
166
'method ' => 'magicMethod ' ,
164
167
'file ' => 'n/a ' ,
165
168
'line ' => 'n/a ' ,
@@ -168,9 +171,9 @@ function () { return 'foo'; },
168
171
169
172
[
170
173
'Callable with class name depending on __callStatic() ' ,
171
- [' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' , 'magicMethod ' ],
174
+ [DummyController::class , 'magicMethod ' ],
172
175
[
173
- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
176
+ 'class ' => DummyController::class ,
174
177
'method ' => 'magicMethod ' ,
175
178
'file ' => 'n/a ' ,
176
179
'line ' => 'n/a ' ,
@@ -179,11 +182,11 @@ function () { return 'foo'; },
179
182
180
183
[
181
184
'Invokable controller ' ,
182
- $ this ,
185
+ $ controller ,
183
186
[
184
- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
187
+ 'class ' => DummyController::class ,
185
188
'method ' => null ,
186
- 'file ' => __FILE__ ,
189
+ 'file ' => $ r3 -> getFileName () ,
187
190
'line ' => $ r3 ->getStartLine (),
188
191
],
189
192
],
@@ -390,35 +393,6 @@ protected function injectController($collector, $controller, $request)
390
393
$ collector ->onKernelController ($ event );
391
394
}
392
395
393
- /**
394
- * Dummy method used as controller callable.
395
- */
396
- public static function staticControllerMethod ()
397
- {
398
- throw new \LogicException ('Unexpected method call ' );
399
- }
400
-
401
- /**
402
- * Magic method to allow non existing methods to be called and delegated.
403
- */
404
- public function __call (string $ method , array $ args )
405
- {
406
- throw new \LogicException ('Unexpected method call ' );
407
- }
408
-
409
- /**
410
- * Magic method to allow non existing methods to be called and delegated.
411
- */
412
- public static function __callStatic (string $ method , array $ args )
413
- {
414
- throw new \LogicException ('Unexpected method call ' );
415
- }
416
-
417
- public function __invoke ()
418
- {
419
- throw new \LogicException ('Unexpected method call ' );
420
- }
421
-
422
396
private function getCookieByName (Response $ response , $ name )
423
397
{
424
398
foreach ($ response ->headers ->getCookies () as $ cookie ) {
@@ -445,7 +419,7 @@ public function testIsJson($contentType, $expected)
445
419
$ this ->assertSame ($ expected , $ c ->isJsonRequest ());
446
420
}
447
421
448
- public function provideJsonContentTypes ()
422
+ public static function provideJsonContentTypes (): array
449
423
{
450
424
return [
451
425
['text/csv ' , false ],
@@ -472,7 +446,7 @@ public function testGetPrettyJsonValidity($content, $expected)
472
446
$ this ->assertSame ($ expected , $ c ->getPrettyJson ());
473
447
}
474
448
475
- public function providePrettyJson ()
449
+ public static function providePrettyJson (): array
476
450
{
477
451
return [
478
452
['null ' , 'null ' ],
0 commit comments