[HttpFoundation] Get response content as resource several times for PHP >= 5.6

This commit is contained in:
Kévin Dunglas 2015-05-24 18:44:31 +02:00 committed by Fabien Potencier
parent cc749a67f6
commit 9f9b0f73aa
2 changed files with 31 additions and 2 deletions

View File

@ -1459,8 +1459,8 @@ class Request
*/
public function getContent($asResource = false)
{
if (false === $this->content || (true === $asResource && null !== $this->content)) {
throw new \LogicException('getContent() can only be called once when using the resource return type.');
if (PHP_VERSION_ID < 50600 && (false === $this->content || (true === $asResource && null !== $this->content))) {
throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.');
}
if (true === $asResource) {

View File

@ -929,11 +929,40 @@ class RequestTest extends \PHPUnit_Framework_TestCase
*/
public function testGetContentCantBeCalledTwiceWithResources($first, $second)
{
if (PHP_VERSION_ID >= 50600) {
$this->markTestSkipped('PHP >= 5.6 allows to open php://input several times.');
}
$req = new Request();
$req->getContent($first);
$req->getContent($second);
}
/**
*
* @dataProvider getContentCantBeCalledTwiceWithResourcesProvider
*/
public function testGetContentCanBeCalledTwiceWithResources($first, $second)
{
if (PHP_VERSION_ID < 50600) {
$this->markTestSkipped('PHP < 5.6 does not allow to open php://input several times.');
}
$req = new Request();
$a = $req->getContent($first);
$b = $req->getContent($second);
if ($first) {
$a = stream_get_contents($a);
}
if ($second) {
$b = stream_get_contents($b);
}
$this->assertEquals($a, $b);
}
public function getContentCantBeCalledTwiceWithResourcesProvider()
{
return array(