[ 'localhost', ], ]); InitializeTenancyByRequestData::$header = 'X-Tenant'; InitializeTenancyByRequestData::$cookie = 'X-Tenant'; InitializeTenancyByRequestData::$queryParameter = '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('X-Tenant', $tenant->id) ->get('test') ->assertSee($tenant->id); }); test('middleware throws exception when tenant data is not provided in the request', function () { pest()->expectException(TenantCouldNotBeIdentifiedByRequestDataException::class); $this->withoutExceptionHandling()->get('test'); });