Skip to content

Commit

Permalink
Fixed getRouteParams() when no parameters are available
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Nov 27, 2016
1 parent eb700a1 commit ba8ec57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion DataCollector/RequestDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,13 @@ public function getRouteParams()
}

$data = $this->data['request_attributes']['_route_params'];
$rawData = $data->getRawData();
if (!isset($rawData[1])) {
return array();
}

$params = array();
foreach ($data->getRawData()[1] as $k => $v) {
foreach ($rawData[1] as $k => $v) {
$params[$k] = $data->seek($k);
}

Expand Down
14 changes: 12 additions & 2 deletions Tests/DataCollector/RequestDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public function testCollect()
$this->assertSame('application/json', $c->getContentType());
}

public function testCollectWithoutRouteParams()
{
$request = $this->createRequest(array());

$c = new RequestDataCollector();
$c->collect($request, $this->createResponse());

$this->assertEquals(array(), $c->getRouteParams());
}

public function testKernelResponseDoesNotStartSession()
{
$kernel = $this->getMock(HttpKernelInterface::class);
Expand Down Expand Up @@ -197,12 +207,12 @@ public function testItIgnoresInvalidCallables()
$this->assertSame('n/a', $c->getController());
}

protected function createRequest()
protected function createRequest($routeParams = array('name' => 'foo'))
{
$request = Request::create('http://test.com/foo?bar=baz');
$request->attributes->set('foo', 'bar');
$request->attributes->set('_route', 'foobar');
$request->attributes->set('_route_params', array('name' => 'foo'));
$request->attributes->set('_route_params', $routeParams);
$request->attributes->set('resource', fopen(__FILE__, 'r'));
$request->attributes->set('object', new \stdClass());

Expand Down

0 comments on commit ba8ec57

Please sign in to comment.