Feb 4, 2017
0
Level 1
$_SERVER population in CLI tests
I'm writing tests using Lumen 5.4 this way:
$this->json('POST', '/oauth/token', [
'grant_type' => 'password',
...
]);
But it returns a 500 error because of a malformed URI. I realized that the $_SERVER variable didn't include information that seems to be needed, so I had to override the LaravelTestCase::call function to fill it (got that "solution" somewhere online):
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['REQUEST_URI'] = str_replace([parse_url($uri, PHP_URL_HOST), parse_url($uri, PHP_URL_SCHEME).'://'], '', $uri);
$_SERVER['REQUEST_METHOD'] = strtoupper($method);
$_SERVER['QUERY_STRING'] = parse_url($uri, PHP_URL_QUERY);
$_SERVER['PATH_INFO'] = str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']);
$_SERVER['CONTENT_TYPE'] = 'application/json';
$_SERVER['argv'] = explode('&', $_SERVER['QUERY_STRING']);
parse_str($_SERVER['QUERY_STRING'], $_GET);
Even then, the $_RE QUEST array is empty. Should I be doing this, which seems like a workaround, or is there any php-cli config missing that I should be looking at?
Please or to participate in this conversation.