[HttpFoundation] Get response content as resource several times for PHP >= 5.6
This commit is contained in:
parent
cc749a67f6
commit
9f9b0f73aa
@ -1459,8 +1459,8 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function getContent($asResource = false)
|
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.');
|
throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true === $asResource) {
|
if (true === $asResource) {
|
||||||
|
@ -929,11 +929,40 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetContentCantBeCalledTwiceWithResources($first, $second)
|
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 = new Request();
|
||||||
$req->getContent($first);
|
$req->getContent($first);
|
||||||
$req->getContent($second);
|
$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()
|
public function getContentCantBeCalledTwiceWithResourcesProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
Reference in New Issue
Block a user