Skip to content

Commit

Permalink
[HttpFoundation] Get response content as resource several times for P…
Browse files Browse the repository at this point in the history
…HP >= 5.6
  • Loading branch information
dunglas authored and fabpot committed Jun 5, 2015
1 parent cc749a6 commit 9f9b0f7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -1459,8 +1459,8 @@ public function isMethodSafe()
*/
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) {
Expand Down
29 changes: 29 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Expand Up @@ -929,11 +929,40 @@ public function testGetContentReturnsResource()
*/
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(
Expand Down

0 comments on commit 9f9b0f7

Please sign in to comment.