Nic*_*Pez 12 api phpunit http-headers
我正在测试我的代码,我的标题有问题.在每个api我使用
$headers = getallheaders();
Run Code Online (Sandbox Code Playgroud)
为了得到它,当我使用app或crhome邮递员扩展测试时,这工作正常.当我开始测试时,就像这样
$client = $this->createClient();
$client->request('GET', '/api/shotcard',
['qrcode'=>'D0m1c173'], [],
['HTTP_API_TOKEN' => 'abc123']
);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
Run Code Online (Sandbox Code Playgroud)
我尝试用带有该测试令牌的用户拍摄带有该qrcode的卡(不是我将在应用程序中使用的令牌),我在这里看到这样的呼叫:https://stackoverflow.com/a/11681422/ 5475228.测试以这种方式失败:
PHP致命错误:在第42行的/var/www/pitstop/src/AppBackendBundle/Controller/ApiController.php中调用未定义的函数AppBackendBundle\Controller\getallheaders()
Mat*_*teo 30
来自这篇文章:
如果您使用Nginx,PHP-FPM或任何其他运行PHP的FastCGI方法,您可能已经注意到该函数
getallheaders()
不存在.野外有许多创造性的解决方法,但PHP提供了两个非常好的功能来缓解您的痛苦.
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;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11394 次 |
最近记录: |