私のコードをテストしていますが、ヘッダに問題があります。各APIの私はそれを得るためにPHPUnit - getallheadersが機能しない
$headers = getallheaders();
を使用して、と私はアプリやcrhome郵便配達の拡張子をテストするとき、これは正常に動作します。 私はそのテスト・トークン(私は、アプリケーションで使用しますないトークン)を持つユーザーでそのQRコードでカードを撃っしようと、私はコールを参照してください。この
$client = $this->createClient();
$client->request('GET', '/api/shotcard',
['qrcode'=>'D0m1c173'], [],
['HTTP_API_TOKEN' => 'abc123']
);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
のように、私のテストを出せここのように:https://stackoverflow.com/a/11681422/5475228そう
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.
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;
}
}
doc:この関数は、apache_request_headers()の別名です。この関数の動作の詳細については、apache_request_headers()のドキュメントを参照してください。 http://php.net/manual/en/function.apache-request-headers.php – Matteo
どのバージョンのPHPを使用していますか? PHP 5.5.7以降でCLIから利用できるようにする必要があります。 – Matteo