PHPUnit - getallheaders not work

i resolve in that way(thanks to https://stackoverflow.com/a/11681422/5475228)

private function request_headers($type, Request $request)
{
    if(function_exists("getallheaders"))
    {
        if($header = getallheaders()[$type])
        {
            return $header;
        }
    }

    return $request->headers->get($type);
}

so the normal request from app get header with getallheaders(), the request from PHPUnit get it from Request object. I don't know why (if someone can explain) but works.


From this article:

If you use Nginx, PHP-FPM or any other FastCGI method of running PHP you’ve probably noticed that the function getallheaders() does not exist. There are many creative workarounds in the wild, but PHP offers two very nice features to ease your pain.

From user contributed comments at getallheaders() function on PHP manual by joyview at gmail dot com

if (!function_exists('getallheaders')) {
    function getallheaders() {
    $headers = [];
    foreach ($_SERVER as $name => $value) {
        if (substr($name, 0, 5) == 'HTTP_') {
            $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
        }
    }
    return $headers;
    }
}