How to specify a different .env file for phpunit in Laravel 5?

前端 未结 10 2344
礼貌的吻别
礼貌的吻别 2020-12-29 05:25

I have a .env file containing my database connection details, as is normal for Laravel 5. I want to override these for testing, which I can do in phpunit.

10条回答
  •  轮回少年
    2020-12-29 05:59

    This is 2019.

    I had this issues for so long until I was able to figure it out.

    And here is my assumption:

    If you are also finding it difficult to make your PHPUnit.xml talk with your .env.testing file, then you are likely using PHPStorm!

    If this is true, continue reading.

    If not, nope...this won't help.

    Ok...

    Here you go:

    1. Go to Settings of your PHPStorm or just simply press Ctrl + Alt + S.
    2. Go to Languages And Frameworks >> PHP >> Test Frameworks
    3. Under Test Runner tab, click Default configuration file and select (by clicking the folder icon) the path of your project's PHPUnit.xml file.

    What this does is to make all your changes in the xml file take effect. So, go ahead, create the .env.testing file, create your preferred DB config variables for test...and try running your tests again!

提交回复
热议问题