From 0a12ce48ffd2a4148ac5ffb12bcec96f97abe302 Mon Sep 17 00:00:00 2001 From: Marcel Hernandez Date: Fri, 5 Aug 2016 15:48:20 +0200 Subject: [PATCH 1/3] [HttpFoundation] fixed testGetContentCanBeCalledTwiceWithResources test After calling Request::getContent(true), subsequent calls to the same instance method (withouth the $asResource flag) always returned false instead of the request body as a plain string. A unit test already existed to guard against this behaviour but it yielded a false positive because it was comparing '' to false using PHPUnit's assertEquals() instead of assertSame(). For completeness sake I also added the missing usage permutations in the test data provider. --- src/Symfony/Component/HttpFoundation/Request.php | 2 +- src/Symfony/Component/HttpFoundation/Tests/RequestTest.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 125be18bbb409..ae771425f7ae0 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1505,7 +1505,7 @@ public function getContent($asResource = false) return $resource; } - $this->content = false; + $this->content = null; return fopen('php://input', 'rb'); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 8540cad6630ee..f10bf8dcb9dba 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1060,12 +1060,14 @@ public function testGetContentCanBeCalledTwiceWithResources($first, $second) $b = stream_get_contents($b); } - $this->assertEquals($a, $b); + $this->assertSame($a, $b); } public function getContentCantBeCalledTwiceWithResourcesProvider() { return array( + 'Fetch then fetch' => array(false, false), + 'Fetch then resource' => array(false, true), 'Resource then fetch' => array(true, false), 'Resource then resource' => array(true, true), ); From 43e960cd14c28145258c37449d707be3b1753a68 Mon Sep 17 00:00:00 2001 From: Marcel Hernandez Date: Fri, 5 Aug 2016 16:24:34 +0200 Subject: [PATCH 2/3] split data provider in two, one for each test --- .../Component/HttpFoundation/Tests/RequestTest.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index f10bf8dcb9dba..f90a368775a16 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1042,8 +1042,16 @@ public function testGetContentCantBeCalledTwiceWithResources($first, $second) $req->getContent($second); } + public function getContentCantBeCalledTwiceWithResourcesProvider() + { + return array( + 'Resource then fetch' => array(true, false), + 'Resource then resource' => array(true, true), + ); + } + /** - * @dataProvider getContentCantBeCalledTwiceWithResourcesProvider + * @dataProvider getContentCanBeCalledTwiceWithResourcesProvider * @requires PHP 5.6 */ public function testGetContentCanBeCalledTwiceWithResources($first, $second) @@ -1063,7 +1071,7 @@ public function testGetContentCanBeCalledTwiceWithResources($first, $second) $this->assertSame($a, $b); } - public function getContentCantBeCalledTwiceWithResourcesProvider() + public function getContentCanBeCalledTwiceWithResourcesProvider() { return array( 'Fetch then fetch' => array(false, false), From e81a6507c08fc4fab181a6c3df9295e5e4e6740a Mon Sep 17 00:00:00 2001 From: Marcel Hernandez Date: Fri, 5 Aug 2016 16:32:37 +0200 Subject: [PATCH 3/3] apparently ->content needs to be able to hold both null and false, depending on the PHP version (<5.6) and the usage pattern --- src/Symfony/Component/HttpFoundation/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index ae771425f7ae0..dc32f4a39af92 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1505,7 +1505,7 @@ public function getContent($asResource = false) return $resource; } - $this->content = null; + $this->content = false; return fopen('php://input', 'rb'); } @@ -1516,7 +1516,7 @@ public function getContent($asResource = false) return stream_get_contents($this->content); } - if (null === $this->content) { + if (null === $this->content || false === $this->content) { $this->content = file_get_contents('php://input'); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy