Skip to content

Instantly share code, notes, and snippets.

@andrey-helldar
Created February 21, 2019 17:39
Show Gist options
  • Save andrey-helldar/631578d2442a93e0bfc76b7aa0c0b841 to your computer and use it in GitHub Desktop.
Save andrey-helldar/631578d2442a93e0bfc76b7aa0c0b841 to your computer and use it in GitHub Desktop.
Loading .env file when running tests
<?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;
}
}
@andrey-helldar
Copy link
Author

Problem: the environment settings file does not load when running tests.
Solution: you must manually load the settings.

Проблема: не загружается файл настроек окружения .env.
Решение: нужно вручную загрузить файл перед сборкой приложения.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment