Created
February 21, 2019 17:39
-
-
Save andrey-helldar/631578d2442a93e0bfc76b7aa0c0b841 to your computer and use it in GitHub Desktop.
Loading .env file when running tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests; | |
use Dotenv\Dotenv; | |
use Illuminate\Contracts\Console\Kernel; | |
use Illuminate\Support\Facades\Hash; | |
trait CreatesApplication | |
{ | |
/** | |
* Creates the application. | |
* | |
* @return \Illuminate\Foundation\Application | |
*/ | |
public function createApplication() | |
{ | |
/** @var \Illuminate\Foundation\Application $app */ | |
$app = require __DIR__ . '/../bootstrap/app.php'; | |
$path = $app->environmentPath(); | |
(new Dotenv($path))->load(); | |
$app->make(Kernel::class)->bootstrap(); | |
Hash::driver('bcrypt')->setRounds(4); | |
return $app; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem: the environment settings file does not load when running tests.
Solution: you must manually load the settings.
Проблема: не загружается файл настроек окружения
.env
.Решение: нужно вручную загрузить файл перед сборкой приложения.