Skip to content

fix: skip unreadable .env in Boot::loadDotEnv for separate-process tests#10417

Open
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/load-dotenv-unreadable-silent
Open

fix: skip unreadable .env in Boot::loadDotEnv for separate-process tests#10417
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/load-dotenv-unreadable-silent

Conversation

@gr8man

@gr8man gr8man commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Description

Test ResponseSendTest::testHeaderOverride fails when tests run in random order because the spawned process (#[RunInSeparateProcess]) calls Boot::loadDotEnv()DotEnv::parse(), which throws InvalidArgumentException when .env exists but is unreadable. The fix adds an early is_file() + is_readable() guard so loadDotEnv() returns silently — .env is optional.

Tests

No new tests — DotEnvTest::testLoadsUnreadableFile already covers the exception path. Verified with:

vendor/bin/phpunit tests/system/HTTP --order-by=random --random-order-seed=1784491692

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.

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we would silently ignore a present but unreadable .env file. Not acceptable.

If you identified the test that causes this, you may configure the test bootstrap to use a controlled environment directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants