3131use Symfony \Component \HttpKernel \Event \ResponseEvent ;
3232use Symfony \Component \HttpKernel \HttpKernel ;
3333use Symfony \Component \HttpKernel \HttpKernelInterface ;
34+ use Symfony \Component \HttpKernel \Tests \Fixtures \DataCollector \DummyController ;
3435
3536class RequestDataCollectorTest extends TestCase
3637{
@@ -91,22 +92,24 @@ public function testControllerInspection($name, $callable, $expected)
9192 $ this ->assertSame ($ expected , $ c ->getController ()->getValue (true ), sprintf ('Testing: %s ' , $ name ));
9293 }
9394
94- public function provideControllerCallables ()
95+ public static function provideControllerCallables (): array
9596 {
9697 // 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 );
100103
101104 // test name, callable, expected
102105 return [
103106 [
104107 '"Regular" callable ' ,
105- [$ this , 'testControllerInspection ' ],
108+ [$ controller , 'regularCallable ' ],
106109 [
107- 'class ' => self ::class,
108- 'method ' => 'testControllerInspection ' ,
109- 'file ' => __FILE__ ,
110+ 'class ' => DummyController ::class,
111+ 'method ' => 'regularCallable ' ,
112+ 'file ' => $ r3 -> getFileName () ,
110113 'line ' => $ r1 ->getStartLine (),
111114 ],
112115 ],
@@ -124,42 +127,42 @@ function () { return 'foo'; },
124127
125128 [
126129 'Static callback as string ' ,
127- __NAMESPACE__ . ' \RequestDataCollectorTest ::staticControllerMethod ' ,
130+ DummyController::class. ' ::staticControllerMethod ' ,
128131 [
129- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
132+ 'class ' => DummyController::class ,
130133 'method ' => 'staticControllerMethod ' ,
131- 'file ' => __FILE__ ,
134+ 'file ' => $ r3 -> getFileName () ,
132135 'line ' => $ r2 ->getStartLine (),
133136 ],
134137 ],
135138
136139 [
137140 'Static callable with instance ' ,
138- [$ this , 'staticControllerMethod ' ],
141+ [$ controller , 'staticControllerMethod ' ],
139142 [
140- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
143+ 'class ' => DummyController::class ,
141144 'method ' => 'staticControllerMethod ' ,
142- 'file ' => __FILE__ ,
145+ 'file ' => $ r3 -> getFileName () ,
143146 'line ' => $ r2 ->getStartLine (),
144147 ],
145148 ],
146149
147150 [
148151 'Static callable with class name ' ,
149- [' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' , 'staticControllerMethod ' ],
152+ [DummyController::class , 'staticControllerMethod ' ],
150153 [
151- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
154+ 'class ' => DummyController::class ,
152155 'method ' => 'staticControllerMethod ' ,
153- 'file ' => __FILE__ ,
156+ 'file ' => $ r3 -> getFileName () ,
154157 'line ' => $ r2 ->getStartLine (),
155158 ],
156159 ],
157160
158161 [
159162 'Callable with instance depending on __call() ' ,
160- [$ this , 'magicMethod ' ],
163+ [$ controller , 'magicMethod ' ],
161164 [
162- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
165+ 'class ' => DummyController::class ,
163166 'method ' => 'magicMethod ' ,
164167 'file ' => 'n/a ' ,
165168 'line ' => 'n/a ' ,
@@ -168,9 +171,9 @@ function () { return 'foo'; },
168171
169172 [
170173 'Callable with class name depending on __callStatic() ' ,
171- [' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' , 'magicMethod ' ],
174+ [DummyController::class , 'magicMethod ' ],
172175 [
173- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
176+ 'class ' => DummyController::class ,
174177 'method ' => 'magicMethod ' ,
175178 'file ' => 'n/a ' ,
176179 'line ' => 'n/a ' ,
@@ -179,11 +182,11 @@ function () { return 'foo'; },
179182
180183 [
181184 'Invokable controller ' ,
182- $ this ,
185+ $ controller ,
183186 [
184- 'class ' => ' Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest ' ,
187+ 'class ' => DummyController::class ,
185188 'method ' => null ,
186- 'file ' => __FILE__ ,
189+ 'file ' => $ r3 -> getFileName () ,
187190 'line ' => $ r3 ->getStartLine (),
188191 ],
189192 ],
@@ -390,35 +393,6 @@ protected function injectController($collector, $controller, $request)
390393 $ collector ->onKernelController ($ event );
391394 }
392395
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-
422396 private function getCookieByName (Response $ response , $ name )
423397 {
424398 foreach ($ response ->headers ->getCookies () as $ cookie ) {
@@ -445,7 +419,7 @@ public function testIsJson($contentType, $expected)
445419 $ this ->assertSame ($ expected , $ c ->isJsonRequest ());
446420 }
447421
448- public function provideJsonContentTypes ()
422+ public static function provideJsonContentTypes (): array
449423 {
450424 return [
451425 ['text/csv ' , false ],
@@ -472,7 +446,7 @@ public function testGetPrettyJsonValidity($content, $expected)
472446 $ this ->assertSame ($ expected , $ c ->getPrettyJson ());
473447 }
474448
475- public function providePrettyJson ()
449+ public static function providePrettyJson (): array
476450 {
477451 return [
478452 ['null ' , 'null ' ],
0 commit comments