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

前端 未结 10 2384
礼貌的吻别
礼貌的吻别 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 06:05

    In your app.php change the Dotenv section

    $envFile = 'testing' === env('APP_ENV') ? '.env.testing' : null;
    try {
        (new Dotenv\Dotenv(__DIR__ . '/../', $envFile))->load();
    } catch (Dotenv\Exception\InvalidPathException $e) {
        //
    }
    

    This will work hence PHPUnit changes the env before loading your app..so if running tests you will have the env already at testing

提交回复
热议问题