Skip to content

Commit 352e956

Browse files
committed
fix: use controlled envDirectory in test bootstrap instead of silencing unreadable .env
Per review feedback, instead of silently skipping an unreadable .env in Boot::loadDotEnv(), configure the test bootstrap to use a controlled environment directory. This ensures separate-process tests don't fail when .env becomes unreadable due to test pollution. - Revert is_file/is_readable guard in Boot::loadDotEnv() (retain production error handling for unreadable .env) - Replace null coalescing with property_exists() for envDirectory - Set $paths->envDirectory = $paths->testsDirectory in test bootstrap
1 parent 9c62951 commit 352e956

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

system/Boot.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,10 @@ public static function preload(Paths $paths): void
204204
*/
205205
protected static function loadDotEnv(Paths $paths): void
206206
{
207-
$envDirectory = $paths->envDirectory ?? $paths->appDirectory . '/../'; // @phpstan-ignore nullCoalesce.property
208-
$dotEnvPath = rtrim($envDirectory, '\\/') . DIRECTORY_SEPARATOR . '.env';
209-
210-
if (! is_file($dotEnvPath) || ! is_readable($dotEnvPath)) {
211-
return;
212-
}
213-
214207
require_once $paths->systemDirectory . '/Config/DotEnv.php';
215-
(new DotEnv($envDirectory))->load();
208+
209+
$envDir = property_exists($paths, 'envDirectory') ? $paths->envDirectory : dirname($paths->appDirectory);
210+
(new DotEnv($envDir))->load();
216211
}
217212

218213
protected static function defineEnvironment(): void

system/Test/bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
require CONFIGPATH . 'Paths.php';
5555
$paths = new Paths();
5656

57+
// Use a controlled environment directory for tests so that
58+
// separate-process tests don't fail on an unreadable .env file.
59+
$paths->envDirectory = $paths->testsDirectory;
60+
5761
// Define necessary framework path constants
5862
defined('APPPATH') || define('APPPATH', realpath(rtrim($paths->appDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
5963
defined('ROOTPATH') || define('ROOTPATH', realpath(APPPATH . '../') . DIRECTORY_SEPARATOR);

0 commit comments

Comments
 (0)