Header 在 Laravel/PHPUnit 测试中掉线

Header getting dropped in Laravel/PHPUnit Testing

我有一个 laravel 5.x 应用程序,单元测试工作正常。现在 php 单元已停止发送带有 http 请求的 headers。我的一个单元测试具有以下代码

 $content='';

    $content = $this->post('users/login', ['password' => 'mypass',
            'email' => 'james.bond@gmail.com'])->response->getContent();

   $data = json_decode($content);
   $token = $data->token;


  $content = $this->put('users/xsettings/0', ['HTTP_Authorization' => $token])->response->getContent();

我在接收端检查了Authorization是否存在,发现请求中没有。

我试过打电话给

$this->refreshApplication()

并尝试使用

$this->call(...)

没有运气。

感谢任何帮助。

提前致谢

Headers是第三个参数不是第二个。

尝试将您的 PUT 请求更改为:

$content = $this->put('users/xsettings/0', [], ['HTTP_Authorization' => $token])->response->getContent();

希望对您有所帮助!