[HttpFoundation] fixed format duplication in Request

This commit is contained in:
Fabien Potencier 2013-09-10 22:34:19 +02:00
parent dc762e10d7
commit 8c2a733528
2 changed files with 11 additions and 6 deletions

View File

@ -406,9 +406,8 @@ class Request
$dup->method = null;
$dup->format = null;
if (!$dup->get('_format')) {
// we set the request format to null if the current request is not known
$dup->setRequestFormat($this->getRequestFormat(null));
if (!$dup->get('_format') && $this->get('_format')) {
$dup->attributes->set('_format', $this->get('_format'));
}
return $dup;

View File

@ -259,9 +259,6 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo=bar', $request->getQueryString());
}
/**
* @covers Symfony\Component\HttpFoundation\Request::duplicate
*/
public function testDuplicate()
{
$request = new Request(array('foo' => 'bar'), array('foo' => 'bar'), array('foo' => 'bar'), array(), array(), array('HTTP_FOO' => 'bar'));
@ -280,6 +277,15 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('foo' => array('foobar')), $dup->headers->all(), '->duplicate() overrides the HTTP header if provided');
}
public function testDuplicateWithFormat()
{
$request = new Request(array(), array(), array('_format' => 'json'));
$dup = $request->duplicate();
$this->assertEquals('json', $dup->getRequestFormat());
$this->assertEquals('json', $dup->attributes->get('_format'));
}
/**
* @covers Symfony\Component\HttpFoundation\Request::getFormat
* @covers Symfony\Component\HttpFoundation\Request::setFormat