-
-
Notifications
You must be signed in to change notification settings - Fork 69
Closed
Labels
Milestone
Description
In ServerRequestFactory::fromGlobals()
, most of the code checks if the arguments are truthy, rather than set. For example:
This becomes an issue during testing (or a long-running process that accepts multiple requests). For example:
// In a previous test
$_POST = ['foo' => 'bar'];
// In current test
$request = ServerRequestFactory::fromGlobals(null, null, []);
echo serialize($request->getParsedBody());
// Expected: a:0:{}
// Actual: a:1:{s:3:"foo";s:3:"bar";}
Improved versions would be:
$server = static::normalizeServer($server ?? $_SERVER);
$files = static::normalizeFiles($files ?? $_FILES);
$cookies ?? $_COOKIE,
$query ?? $_GET,
$body ?? $_POST,
Or for under PHP 7:
$server = static::normalizeServer(isset($server) ? $server : $_SERVER);
$files = static::normalizeFiles(isset($files) ? $files : $_FILES);
isset($cookies) ? $cookies : $_COOKIE,
isset($query) ? $query : $_GET,
isset($body) ? $body : $_POST,
(This code should fix the issues, but I didn't have time to write any tests right now, so I'm opening an issue instead of a pr.)
Originally posted by @0b10011 at zendframework/zend-diactoros#281