Skip to content
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