You are here

public function RequestDataCollectorTest::testControllerInspection in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/Tests/DataCollector/RequestDataCollectorTest.php \Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest::testControllerInspection()

Test various types of controller callables.

File

vendor/symfony/http-kernel/Tests/DataCollector/RequestDataCollectorTest.php, line 57

Class

RequestDataCollectorTest

Namespace

Symfony\Component\HttpKernel\Tests\DataCollector

Code

public function testControllerInspection() {

  // make sure we always match the line number
  $r1 = new \ReflectionMethod($this, 'testControllerInspection');
  $r2 = new \ReflectionMethod($this, 'staticControllerMethod');
  $r3 = new \ReflectionClass($this);

  // 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',
      ),
    ),
    array(
      'Invokable controller',
      $this,
      array(
        'class' => 'Symfony\\Component\\HttpKernel\\Tests\\DataCollector\\RequestDataCollectorTest',
        'method' => null,
        'file' => __FILE__,
        'line' => $r3
          ->getStartLine(),
      ),
    ),
  );
  $c = new RequestDataCollector();
  $request = $this
    ->createRequest();
  $response = $this
    ->createResponse();
  foreach ($controllerTests as $controllerTest) {
    $this
      ->injectController($c, $controllerTest[1], $request);
    $c
      ->collect($request, $response);
    $this
      ->assertSame($controllerTest[2], $c
      ->getController(), sprintf('Testing: %s', $controllerTest[0]));
  }
}