Skip to content

Commit

Permalink
bug #20239 [HttpKernel] Fix a regression in the RequestDataCollector …
Browse files Browse the repository at this point in the history
…(jakzal)

This PR was merged into the 3.1 branch.

Discussion
----------

[HttpKernel] Fix a regression in the RequestDataCollector

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19701
| License       | MIT
| Doc PR        | -

The regression was introduced by refactoring made as part of #17589 (if/else statements where rearranged).

Commits
-------

57008ea [HttpKernel] Fix a regression in the RequestDataCollector
26b90e4 [HttpKernel] Refactor a RequestDataCollector test case to use a data provider
  • Loading branch information
fabpot committed Oct 22, 2016
2 parents 57f8d1e + 57008ea commit aa75adf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
Expand Up @@ -374,7 +374,7 @@ protected function parseController($controller)
);
}

return (string) $controller ?: 'n/a';
return is_string($controller) ? $controller : 'n/a';
}

private function getCookieHeader($name, $value, $expires, $path, $domain, $secure, $httponly)
Expand Down
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\HttpKernel\Tests\DataCollector;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
Expand Down Expand Up @@ -70,16 +71,28 @@ public function testKernelResponseDoesNotStartSession()
}

/**
* Test various types of controller callables.
* @dataProvider provideControllerCallables
*/
public function testControllerInspection()
public function testControllerInspection($name, $callable, $expected)
{
$c = new RequestDataCollector();
$request = $this->createRequest();
$response = $this->createResponse();
$this->injectController($c, $callable, $request);
$c->collect($request, $response);

$this->assertSame($expected, $c->getController(), sprintf('Testing: %s', $name));
}

public function provideControllerCallables()
{
// 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(
return array(
array(
'"Regular" callable',
array($this, 'testControllerInspection'),
Expand Down Expand Up @@ -168,15 +181,17 @@ function () { return 'foo'; },
),
),
);
}

public function testItIgnoresInvalidCallables()
{
$request = $this->createRequestWithSession();
$response = new RedirectResponse('/');

$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]));
}
$c->collect($request, $response);

$this->assertSame('n/a', $c->getController());
}

protected function createRequest()
Expand All @@ -191,6 +206,16 @@ protected function createRequest()
return $request;
}

private function createRequestWithSession()
{
$request = $this->createRequest();
$request->attributes->set('_controller', 'Foo::bar');
$request->setSession(new Session(new MockArraySessionStorage()));
$request->getSession()->start();

return $request;
}

protected function createResponse()
{
$response = new Response();
Expand Down

0 comments on commit aa75adf

Please sign in to comment.