[ 'localhost', ], 'tenancy.identification.' . RequestDataTenantResolver::class . '.header' => 'X-Tenant', 'tenancy.identification.' . RequestDataTenantResolver::class . '.query_parameter' => 'tenant', 'tenancy.identification.' . RequestDataTenantResolver::class . '.cookie' => 'tenant', ]); Route::middleware(['tenant', InitializeTenancyByRequestData::class])->get('/test', function () { return 'Tenant id: ' . tenant('id'); }); }); test('header identification works', function () { $tenant = Tenant::create(); $this ->withoutExceptionHandling() ->withHeader('X-Tenant', $tenant->id) ->get('test') ->assertSee($tenant->id); }); test('query parameter identification works', function () { $tenant = Tenant::create(); $this ->withoutExceptionHandling() ->get('test?tenant=' . $tenant->id) ->assertSee($tenant->id); }); test('cookie identification works', function () { $tenant = Tenant::create(); $this ->withoutExceptionHandling() ->withUnencryptedCookie('tenant', $tenant->id) ->get('test') ->assertSee($tenant->id); }); // todo@tests encrypted cookie test('middleware throws exception when tenant data is not provided in the request', function () { pest()->expectException(TenantCouldNotBeIdentifiedByRequestDataException::class); $this->withoutExceptionHandling()->get('test'); });