bug #20239 [HttpKernel] Fix a regression in the RequestDataCollector (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 RequestDataCollector26b90e4
[HttpKernel] Refactor a RequestDataCollector test case to use a data provider
This commit is contained in:
commit
aa75adf8bb
@ -374,7 +374,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
);
|
||||
}
|
||||
|
||||
return (string) $controller ?: 'n/a';
|
||||
return is_string($controller) ? $controller : 'n/a';
|
||||
}
|
||||
|
||||
private function getCookieHeader($name, $value, $expires, $path, $domain, $secure, $httponly)
|
||||
|
@ -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;
|
||||
@ -70,16 +71,28 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'),
|
||||
@ -168,15 +181,17 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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()
|
||||
@ -191,6 +206,16 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
|
||||
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();
|
||||
|
Reference in New Issue
Block a user