Skip to content

Commit 26b90e4

Browse files
committed
[HttpKernel] Refactor a RequestDataCollector test case to use a data provider
1 parent f07bf03 commit 26b90e4

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,28 @@ public function testKernelResponseDoesNotStartSession()
7070
}
7171

7272
/**
73-
* Test various types of controller callables.
73+
* @dataProvider provideControllerCallables
7474
*/
75-
public function testControllerInspection()
75+
public function testControllerInspection($name, $callable, $expected)
76+
{
77+
$c = new RequestDataCollector();
78+
$request = $this->createRequest();
79+
$response = $this->createResponse();
80+
$this->injectController($c, $callable, $request);
81+
$c->collect($request, $response);
82+
83+
$this->assertSame($expected, $c->getController(), sprintf('Testing: %s', $name));
84+
}
85+
86+
public function provideControllerCallables()
7687
{
7788
// make sure we always match the line number
7889
$r1 = new \ReflectionMethod($this, 'testControllerInspection');
7990
$r2 = new \ReflectionMethod($this, 'staticControllerMethod');
8091
$r3 = new \ReflectionClass($this);
92+
8193
// test name, callable, expected
82-
$controllerTests = array(
94+
return array(
8395
array(
8496
'"Regular" callable',
8597
array($this, 'testControllerInspection'),
@@ -168,15 +180,6 @@ function () { return 'foo'; },
168180
),
169181
),
170182
);
171-
172-
$c = new RequestDataCollector();
173-
$request = $this->createRequest();
174-
$response = $this->createResponse();
175-
foreach ($controllerTests as $controllerTest) {
176-
$this->injectController($c, $controllerTest[1], $request);
177-
$c->collect($request, $response);
178-
$this->assertSame($controllerTest[2], $c->getController(), sprintf('Testing: %s', $controllerTest[0]));
179-
}
180183
}
181184

182185
protected function createRequest()

0 commit comments

Comments
 (0)