From 6a88664ea3864e679b9835a276a7634a5be9f62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 24 May 2015 18:44:31 +0200 Subject: [PATCH 1/3] [HttpFoundation] Get response content as resource several times for PHP > 5.6 --- .../Component/HttpFoundation/Request.php | 2 +- .../HttpFoundation/Tests/RequestTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index f2ee1829e5211..ef6a9b6d0da5b 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1459,7 +1459,7 @@ public function isMethodSafe() */ public function getContent($asResource = false) { - if (false === $this->content || (true === $asResource && null !== $this->content)) { + 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.'); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index d13228e5561e9..cabeaa96cc013 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -929,6 +929,24 @@ 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(); $req->getContent($first); $req->getContent($second); From 07b0fc49e7710e79785589bebaf1ac694cf32b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 28 May 2015 12:30:26 +0200 Subject: [PATCH 2/3] [HttpFoundation] Clarified resource exception message. --- src/Symfony/Component/HttpFoundation/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index ef6a9b6d0da5b..9e94407ec59fd 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1460,7 +1460,7 @@ public function isMethodSafe() public function getContent($asResource = false) { 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.'); + throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.'); } if (true === $asResource) { From c0d635645bf406ae6edaf9984ab8c0e4ec86a41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 2 Jun 2015 14:42:05 +0200 Subject: [PATCH 3/3] [HttpFoundation] Add an assertion in resource test. --- .../HttpFoundation/Tests/RequestTest.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index cabeaa96cc013..990d3a842d097 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -939,6 +939,7 @@ public function testGetContentCantBeCalledTwiceWithResources($first, $second) } /** + * * @dataProvider getContentCantBeCalledTwiceWithResourcesProvider */ public function testGetContentCanBeCalledTwiceWithResources($first, $second) @@ -948,8 +949,18 @@ public function testGetContentCanBeCalledTwiceWithResources($first, $second) } $req = new Request(); - $req->getContent($first); - $req->getContent($second); + $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()