8000 bug #20652 Fixed getRouteParams() when no parameters are available (w… · Padam87/symfony@cb03103 · GitHub
[go: up one dir, main page]

Skip to content

Commit cb03103

Browse files
bug symfony#20652 Fixed getRouteParams() when no parameters are available (wouterj)
This PR was merged into the 3.2 branch. Discussion ---------- Fixed getRouteParams() when no parameters are available | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#20650 | License | MIT | Doc PR | - Commits ------- 040da81 Fixed getRouteParams() when no parameters are available
2 parents 02dc4be + 040da81 commit cb03103

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,13 @@ public function getRouteParams()
276276
}
277277

278278
$data = $this->data['request_attributes']['_route_params'];
279+
$rawData = $data->getRawData();
280+
if (!isset($rawData[1])) {
281+
return array();
282+
}
283+
279284
$params = array();
280-
foreach ($data->getRawData()[1] as $k => $v) {
285+
foreach ($rawData[1] as $k => $v) {
281286
$params[$k] = $data->seek($k);
282287
}
283288

src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ public function testCollect()
5959
$this->assertSame('application/json', $c->getContentType());
6060
}
6161

62+
public function testCollectWithoutRouteParams()
63+
{
64+
$request = $this->createRequest(array());
65+
66+
$c = new RequestDataCollector();
67+
$c->collect($request, $this->createResponse());
68+
69+
$this->assertEquals(array(), $c->getRouteParams());
70+
}
71+
6272
public function testKernelResponseDoesNotStartSession()
6373
{
6474
$kernel = $this->getMock(HttpKernelInterface::class);
@@ -197,12 +207,12 @@ public function testItIgnoresInvalidCallables()
197207
$this->assertSame('n/a', $c->getController());
198208
}
199209

200-
protected function createRequest()
210+
protected function createRequest($routeParams = array('name' => 'foo'))
201211
{
202212
$request = Request::create('http://test.com/foo?bar=baz');
203213
$request->attributes->set('foo', 'bar');
204214
$request->attributes->set('_route', 'foobar');
205-
$request->attributes->set('_route_params', array('name' => 'foo'));
215+
$request->attributes->set('_route_params', $routeParams);
206216
$request->attributes->set('resource', fopen(__FILE__, 'r'));
207217
$request->attributes->set('object', new \stdClass());
208218

0 commit comments

Comments
 (0)
0