skip to Main Content

I want to have a .env.testing file for my tests, specifically for setting a local testing database. But do I have to copy everything from .env into .env.testing, just to change one line? Can’t I do some command that tells php artisan test that I want to load everything from .env, and then override DB_DATABASE by having only this line in .env.testing?

2

Answers


  1. Chosen as BEST ANSWER

    I ended up just changing this line in my phpunit.xml file:

    <env name="DB_DATABASE" value="projectdb_testing"/>
    

    It even was already there, I just had to uncomment it and change the database name.


  2. if you want to change the env system of Laravel, you can override this method in the App/Http/Kernel.php file

    public function bootstrap() 
    {
        app()->loadEnvironmentFrom('.env.test');
        parent::bootstrap(); 
    }
    

    I think it’s a bit tricky and dangerous to change Laravel env system, but you can analyze how it’s working by reading methods in the file vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadEnvironmentVariables.php

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search