diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index f2ee1829e5..9e94407ec5 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -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) { diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index d13228e556..990d3a842d 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -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(