我用这种方式使用Lumen 5.4编写测试:
$this->json('POST', '/oauth/token', [
'grant_type' => 'password',
...
]);
但由于URI格式错误,它会返回500错误。我意识到$ _SERVER变量并不包含似乎需要的信息,所以我不得不重写LaravelTestCase :: call函数来填充它(得到那个&#34;解决方案&#34;某处在线):< / p>
$_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);
即使这样,$ _REQUEST数组也是空的。我应该这样做,这似乎是一种解决方法,或者是否有任何我应该关注的php-cli配置?