From f308ed9181a46ff3070a9f990a59a35caf8ef24f Mon Sep 17 00:00:00 2001 From: Darko Gjorgjijoski Date: Sat, 22 Aug 2026 14:58:34 +0200 Subject: [PATCH] fix(tests): tolerate a missing .env in the environment-writing pilot tests CI checkouts have no .env, so the backup-and-restore pattern in the installation and set-domain tests fatally failed on the first read. The tests now seed .env from .env.example when absent, the way an installer would, and remove it again afterwards. Developer machines are unaffected. --- .../PilotSpec/InstallationDatabaseConfigTest.php | 12 +++++++++++- tests/Feature/PilotSpec/SetDomainTest.php | 12 +++++++++++- tests/Feature/PilotSpec/ZzDatabaseRefusalTest.php | 12 +++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/tests/Feature/PilotSpec/InstallationDatabaseConfigTest.php b/tests/Feature/PilotSpec/InstallationDatabaseConfigTest.php index 78436e23..8a716b45 100644 --- a/tests/Feature/PilotSpec/InstallationDatabaseConfigTest.php +++ b/tests/Feature/PilotSpec/InstallationDatabaseConfigTest.php @@ -11,11 +11,21 @@ use function Pest\Laravel\postJson; beforeEach(function () { Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]); + // CI has no .env; seed one the way an installer would so the + // env-writing paths under test have a real file to work against. + $this->envExisted = file_exists(base_path('.env')); + if (! $this->envExisted) { + copy(base_path('.env.example'), base_path('.env')); + } $this->envBackup = file_get_contents(base_path('.env')); }); afterEach(function () { - file_put_contents(base_path('.env'), $this->envBackup); + if ($this->envExisted) { + file_put_contents(base_path('.env'), $this->envBackup); + } else { + @unlink(base_path('.env')); + } }); it('returns connection defaults per driver', function () { diff --git a/tests/Feature/PilotSpec/SetDomainTest.php b/tests/Feature/PilotSpec/SetDomainTest.php index 21d4598f..3a45bf87 100644 --- a/tests/Feature/PilotSpec/SetDomainTest.php +++ b/tests/Feature/PilotSpec/SetDomainTest.php @@ -8,11 +8,21 @@ use function Pest\Laravel\putJson; beforeEach(function () { Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]); + // CI has no .env; seed one the way an installer would so the + // env-writing paths under test have a real file to work against. + $this->envExisted = file_exists(base_path('.env')); + if (! $this->envExisted) { + copy(base_path('.env.example'), base_path('.env')); + } $this->envBackup = file_get_contents(base_path('.env')); }); afterEach(function () { - file_put_contents(base_path('.env'), $this->envBackup); + if ($this->envExisted) { + file_put_contents(base_path('.env'), $this->envBackup); + } else { + @unlink(base_path('.env')); + } }); it('requires a domain', function () { diff --git a/tests/Feature/PilotSpec/ZzDatabaseRefusalTest.php b/tests/Feature/PilotSpec/ZzDatabaseRefusalTest.php index f6608474..dec8304c 100644 --- a/tests/Feature/PilotSpec/ZzDatabaseRefusalTest.php +++ b/tests/Feature/PilotSpec/ZzDatabaseRefusalTest.php @@ -13,11 +13,21 @@ uses()->group('isolated'); beforeEach(function () { Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]); + // CI has no .env; seed one the way an installer would so the + // env-writing paths under test have a real file to work against. + $this->envExisted = file_exists(base_path('.env')); + if (! $this->envExisted) { + copy(base_path('.env.example'), base_path('.env')); + } $this->envBackup = file_get_contents(base_path('.env')); }); afterEach(function () { - file_put_contents(base_path('.env'), $this->envBackup); + if ($this->envExisted) { + file_put_contents(base_path('.env'), $this->envBackup); + } else { + @unlink(base_path('.env')); + } }); it('refuses a database that already contains data, without touching the environment file', function () {