-
Notifications
You must be signed in to change notification settings - Fork 11.4k
.env.testing not being loaded at all #55532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.env.testing not being loaded at all #55532
Comments
Just a note: I've just tested an app on Laravel 11 using the same environment described above and it worked fine. |
Do you have https://github.com/laravel/laravel/blob/f6e4638ee6ca1cd40aa7c56311d89ea3d91a24f8/phpunit.xml#L21 |
for work arround, just put this in your phpunit.xml
|
That is not a workaround. That’s where you set the environment so it knows which .env to use. |
@utsavsomaiya which version of the framework you using? |
@VictorMLima98: I was having this issue just now and came here to look for others reporting it. One thing that differed with my environment was that I had just upgraded from I ran |
Sorry for the late reply, guys. I've managed to get around this issue by downgrading my project a few minor versions. I'm using 12.8.1 and the issue no longer takes place. I bet that's a problem that has been introduced on 12.10 or something like that. I tried to debug the framework files for a few hours without success, so I just downgraded and boom, problem's gone. |
Actually it just happened again on 12.8.1. Tried upgrading to 12.12 and it persists. |
@VictorMLima98: I assume after switching versions, you're running a |
Sure! I even deleted my whole vendor folder and re-installed it, but no solution yet :/ |
Confirmed. Having same problem in v12.12.0. Also in Sail Testing e.g. user creation creates a user (with dusk) in the regular database, and not the testing database). |
Laravel Version
12.10.1
PHP Version
8.4.1
Database Driver & Version
MySQL 9.2.0
Description
.env.testing
is not loaded when runningphp artisan test
on Laravel 12I'm running a Laravel 12 project, and I’m having trouble getting the
.env.testing
file to load when running tests viaphp artisan test
.According to the docs,
.env.testing
should be loaded automatically when running tests using Artisan. However, this does not seem to be happening in my setup.Expected Behavior
Laravel should load .env.testing and use the environment variables defined in it.
Actual Behavior
Laravel loads the default .env file.
The environment remains local, and the DB_DATABASE is not coming from .env.testing.
This means tests are running against the development database.
Additional Info
.env.testing
is correctly placed in the project root.app()->environmentFile()
still returns .env.php artisan my-command --env=testing
loads.env.testing
correctly, but runningartisan test
does notSteps To Reproduce
.env.testing
file in the project root with:You can also try to migrate the testing database with
php artisan migrate --env=testing
and see if your development database got refreshed, which is my case.The text was updated successfully, but these errors were encountered: