Hi
I've created this issue on Laravel's Github repository and I think it's a bug!
You can find it here: https://github.com/laravel/framework/issues/43409
Description:
Phpunit.xml variables are not loaded on abstract TestCase!
After clearing cache, config, etc., php artisan config:clear, php artisan optimize:clear,...
I was unable to create a test environment with different DB.
It is not possible for me to get the test environment variable.
Steps To Reproduce:
There are 2 ways to see the bug:
after changing you phpunit.xml file in your Abstract TestCase add this method and you can see the result:
protected function setUp(): void
{
parent::setUp();
dump(env('APP_NAME'));
dd(env('APP_ENV'));
}
After clearing cache, run test command (php artisan test)
change your bootstrap/app.php:
Create .env.testing file and change your app file:
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
$app->loadEnvironmentFrom('.env.testing');
dump(env('APP_NAME')); // still load from .env
dd(env('APP_ENV')); // still load from .env
I have change the env tag in phpunit.xml to server it works!
<server name="APP_NAME" value="testing"/>
<server name="APP_ENV" value="testing"/>
But still I can not load variables from .env.testing
Update:
here also you can see someone in docker environment solved the problem!
https://stackoverflow.com/questions/45922358/why-phpunit-is-not-getting-the-correct-app-env-as-specified-in-phpunit-xml