Tests can wipe the dev database: phpunit.xml env vars are not forced #53
Labels
No labels
app
backlog
bug
ci-cd
contribution welcome
duplicate
enhancement
good first issue
help wanted
question
testing
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lvl0/dishplanner#53
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Impact
A test run wiped the local dev database (
dishplanner). Symptom: logged out of the local app mid-run, becauseSESSION_DRIVER=filesessions key off ausersrow that no longer existed.49 of 59 test files use
RefreshDatabase, which runsmigrate:fresh— drop all tables, re-migrate — against whatever connection resolves at bootstrap.Root cause
phpunit.xmldeclares its test environment with bare<env>entries and noforce="true":<env>withoutforcesets a default — it does not overwrite a variable that is already present in the environment.<server>writes to$_SERVER, which is where Laravel's config actually resolves from, andforce="true"overwrites unconditionally.So whenever phpunit is launched in a process that already has the container's
.envloaded (APP_ENV=local,DB_CONNECTION=mysql,DB_DATABASE=dishplanner), the real dev database wins andRefreshDatabasedrops it..env.testingdoes not help here: Laravel only loads it whenAPP_ENV=testing, and nothing sets that in this path.Reference: ffr is immune, and shows why
ffrhas more exposure by volume — 100 of 121 test files useRefreshDatabase— and has never been wiped, because itsphpunit.xmlforces every value:Audit across projects:
force="true"<server><env>Same tooling, same
RefreshDatabasepattern, opposite outcomes. The only thing protecting ffr isforce="true".Fix
Rewrite the
<php>block inphpunit.xmlto match ffr: convert each<env>to<server>withforce="true", keeping one<env name="APP_ENV" value="testing" force="true"/>alongside the<server>equivalent.This makes the repo defend itself on every invocation path — MCP tooling,
shell.nixhelpers, CI, manual runs — instead of depending on the caller to inject the right environment.Notes
.env.testing,.env.dusk.local, andphpunit.dusk.xmlare all correct and need no change..env.dusk.locallegitimately uses MySQL (dishplanner_test), since Dusk needs a real server.container-devMCP server has been patched separately to inject.env.testingand refuse to run against a non-test database. That is defense in depth and lives outside this repo; it does not remove the need for this fix.troveuses<server>but with zeroforceattributes, so it has the same latent gap.Acceptance
phpunit.xml<php>block uses<server>+force="true"for every valueAPP_ENV=localin the environment still resolves to sqlite:memory:and leaves thedishplannerdatabase untouched