Test various types of controller callables.
@dataProvider provider
public function testControllerInspection(Request $request, Response $response) {
// make sure we always match the line number
$r1 = new \ReflectionMethod($this, 'testControllerInspection');
$r2 = new \ReflectionMethod($this, 'staticControllerMethod');
// test name, callable, expected
$controllerTests = array(
array(
'"Regular" callable',
array(
$this,
'testControllerInspection',
),
array(
'class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest',
'method' => 'testControllerInspection',
'file' => __FILE__,
'line' => $r1
->getStartLine(),
),
),
array(
'Closure',
function () {
return 'foo';
},
array(
'class' => __NAMESPACE__ . '\\{closure}',
'method' => null,
'file' => __FILE__,
'line' => __LINE__ - 5,
),
),
array(
'Static callback as string',
'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest::staticControllerMethod',
'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest::staticControllerMethod',
),
array(
'Static callable with instance',
array(
$this,
'staticControllerMethod',
),
array(
'class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest',
'method' => 'staticControllerMethod',
'file' => __FILE__,
'line' => $r2
->getStartLine(),
),
),
array(
'Static callable with class name',
array(
'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest',
'staticControllerMethod',
),
array(
'class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest',
'method' => 'staticControllerMethod',
'file' => __FILE__,
'line' => $r2
->getStartLine(),
),
),
array(
'Callable with instance depending on __call()',
array(
$this,
'magicMethod',
),
array(
'class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest',
'method' => 'magicMethod',
'file' => 'n/a',
'line' => 'n/a',
),
),
array(
'Callable with class name depending on __callStatic()',
array(
'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest',
'magicMethod',
),
array(
'class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest',
'method' => 'magicMethod',
'file' => 'n/a',
'line' => 'n/a',
),
),
);
$c = new RequestDataCollector();
foreach ($controllerTests as $controllerTest) {
$this
->injectController($c, $controllerTest[1], $request);
$c
->collect($request, $response);
$this
->assertEquals($controllerTest[2], $c
->getController(), sprintf('Testing: %s', $controllerTest[0]));
}
}