【发布时间】:2016-03-25 02:17:15
【问题描述】:
我正在尝试使用 phpunit 测试我用 laravel 5 编写的 Web 服务。我是这个测试框架的新手。应用程序使用 JWT 进行身份验证,该身份验证在请求的标头中传递。
我的测试看起来像这样:
$response = $this->call('POST', 'authenticate', [
'username' => 'carparts',
'email' => 'admin@admin.com',
'password' => 'password'
]);
$token = 'Bearer ' . json_decode($response->getContent())->token;
$response = $this->call('POST', 'users', [
"first_name" => "Test",
"last_name" => "Test",
"email" => 'test@test.com',
"password" => "testing",
"role" => "1"
], [], [], [
'Authorization' => $token
]);
dd($response->getContent());
令牌返回正常,但是当我尝试在下一个请求中使用创建新用户时,它失败说无法从请求中解析令牌。当我在中间件中执行request()->headers 进行检查时,即使这样也不会显示标题。我究竟做错了什么?如何使用 PHPUnit 在请求中传递标头?
【问题讨论】:
标签: php testing http-headers phpunit