Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpKernel] Fix a regression in the RequestDataCollector #20239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.