【发布时间】:2017-05-16 14:12:19
【问题描述】:
我正在测试我的代码,但标题有问题。在我使用的每个 api 中
$headers = getallheaders();
要做到这一点,当我使用应用程序或 crhome 邮递员扩展程序进行测试时,这可以正常工作。 当我启动我的测试时,像这样
$client = $this->createClient();
$client->request('GET', '/api/shotcard',
['qrcode'=>'D0m1c173'], [],
['HTTP_API_TOKEN' => 'abc123']
);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
我尝试使用该 qrcode 与具有该测试令牌(不是我将在应用程序中使用的令牌)的用户一起拍摄一张卡片,我在这里看到这样的调用:https://stackoverflow.com/a/11681422/5475228。 测试以这种方式失败:
PHP 致命错误:在第 42 行的 /var/www/pitstop/src/AppBackendBundle/Controller/ApiController.php 中调用未定义函数 AppBackendBundle\Controller\getallheaders()
【问题讨论】:
-
来自文档:此函数是 apache_request_headers() 的别名。请阅读 apache_request_headers() 文档以获取有关此函数如何工作的更多信息。 php.net/manual/en/function.apache-request-headers.php
-
您使用的是哪个版本的php?自 PHP 5.5.7 起,它应该可以从 CLI 获得
标签: api http-headers phpunit