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?
<env name="APP_ENV" value="testing"/>
has no effect in the bootstrap script. I had to addputenv('APP_ENV=testing');
manually before creating the application. If this is not the case for you, you may be able to use this as a workaround. – Drank