I have some problems with getting Laravel to load the proper .env file for my testcases. I'm using PHPUnit with the following var set in phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
<exclude>
<file>./app/Http/routes.php</file>
</exclude>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>
In my .env.testing file i have:
APP_ENV=testing
DB_CONNECTION=sqlite
And i have his connection set up under config/database.php:
'sqlite' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => ''
]
It just isn't loading the .env.testing file. If i do this in my TestCase.php:
dd(env('APP_ENV'));
I still get "development" from my .env file
I have also tried using:
$app->loadEnvironmentFrom('.env.testing');
Like suggested in the thread here
Does anyone have an idea to what could be wrong?
My problem was quite similar. Env file .env.testing was not read at all. I tried to put some var_dump everywhere in my test file, everything was ok but even a var_dump(env("APP_NAME")) was null.
I figured to type a "php artisan config:clear" and everything was back to normal. Not sure what I've done but it worked for me :)
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