'DatabaseSeeder', '--force' => true]); $this->envBackup = file_get_contents(base_path('.env')); }); afterEach(function () { file_put_contents(base_path('.env'), $this->envBackup); }); it('requires a domain', function () { putJson('/api/v1/installation/set-domain', [])->assertStatus(422); }); it('always writes the session domain as the host portion of the submitted value', function () { config(['app.url' => 'http://pilot.test']); putJson('/api/v1/installation/set-domain', ['app_domain' => 'http://other.test']) ->assertOk() ->assertJson(['success' => true]); $env = file_get_contents(base_path('.env')); expect($env)->toContain('SESSION_DOMAIN=other.test'); }); it('writes the stateful-domains entry when the submitted domain differs from the current one', function () { config(['app.url' => 'http://pilot.test']); putJson('/api/v1/installation/set-domain', ['app_domain' => 'elsewhere.test'])->assertOk(); $env = file_get_contents(base_path('.env')); expect($env)->toContain('SANCTUM_STATEFUL_DOMAINS=elsewhere.test'); expect($env)->toContain('SESSION_DOMAIN=elsewhere.test'); }); it('replaces an existing key in place rather than appending a duplicate', function () { config(['app.url' => 'http://pilot.test']); putJson('/api/v1/installation/set-domain', ['app_domain' => 'first.test'])->assertOk(); putJson('/api/v1/installation/set-domain', ['app_domain' => 'second.test'])->assertOk(); $env = file_get_contents(base_path('.env')); expect(substr_count($env, "\nSESSION_DOMAIN=") + (str_starts_with($env, 'SESSION_DOMAIN=') ? 1 : 0)) ->toBe(1); expect($env)->toContain('SESSION_DOMAIN=second.test'); });