Skip to content

Commit 9c62951

Browse files
committed
fix: silently skip unreadable .env file in loadDotEnv()
The loadDotEnv() method now checks if the .env file exists and is readable before attempting to load it. This prevents a fatal error when tests run in separate processes (e.g. with @RunInSeparateProcess) where the .env file may not be accessible. Fixes testHeaderOverride error in ResponseSendTest.
1 parent b635434 commit 9c62951

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎system/Boot.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,14 @@ public static function preload(Paths $paths): void
204204
*/
205205
protected static function loadDotEnv(Paths $paths): void
206206
{
207-
require_once $paths->systemDirectory . '/Config/DotEnv.php';
208207
$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+
214+
require_once $paths->systemDirectory . '/Config/DotEnv.php';
209215
(new DotEnv($envDirectory))->load();
210216
}
211217

0 commit comments

Comments
 (0)