Php Laravel头在测试时为空

Php Laravel头在测试时为空,php,laravel,testing,phpunit,laravel-testing,Php,Laravel,Testing,Phpunit,Laravel Testing,我正在使用基于帐户模型的Laravel构建一个多租户api,我通过在所有租户模型上使用trait(AccountScoped)来确定请求读取器“Account”正在使用的tennant,所有工作都在postman上进行,但在trait中无法测试标头 帐户已映射(特征) 试验方法: public function testActionIndexInController() { $categories = Category::where('account_id',$this->acco

我正在使用基于帐户模型的Laravel构建一个多租户api,我通过在所有租户模型上使用trait(AccountScoped)来确定请求读取器“Account”正在使用的tennant,所有工作都在postman上进行,但在trait中无法测试标头

帐户已映射(特征)

试验方法:

public function testActionIndexInController()
{
    $categories = Category::where('account_id',$this->account->id)->get()->toJSON();
    $response = $this->actingAs($this->user, 'api')
                    ->withHeader('Account',$this->account->id)
                    ->get(route('categories.index'));

    $response->assertStatus(200)->assertSee($categories);
}
*$this->user是具有帐户的用户实例模型,$this->account是与所选用户相关的帐户实例

但是当我运行测试时,我在$account\u id上得到空值

当我通过邮递员提出同样的要求时,价值就在那里

如果您正在使用jwt,则可以在测试模式下使用此代码设置请求

if (env('APP_ENV') === 'testing') {
     JWTAuth::setRequest($request);
}
否则,您需要使用Illumb\Http\request设置请求; 另外,您可以尝试使用此代码来获取标题

\Illuminate\Support\Facades\Request::instance()->headers->get('Account')

我对控制器上的action store进行了相同的测试,所有测试都非常完美
\Illuminate\Support\Facades\Request::instance()->headers->get('Account')