In Laravel 5.1 TestCase, the baseUrl is hard-coded. I'd like to set it based on the value I have set in .env.
How do I access the .env variables within the TestCase class?
in Laravel 5.0 TestCase
, I can get .env variable with following function.
getenv('APP_VARIABLE');
I think it should work with Laravel 5.1 as well as getenv()
is a PHP function.
Start Dotenv
to get .env variables in the TestCase stage
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
Dotenv::load(__DIR__.'/../');
$this->baseUrl = env('APP_URL', $this->baseUrl);
return $app;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With