There's a fresh Laravel installation inside a blog folder. I have only removed the default .env file and added:

dd(config('app.env'));

to a CreatesApplication.php

Run

docker-compose up

or if you don't have a compose:

docker run --env APP_ENV=docker -w /src -v "$PWD/blog":/src php:7.4 php artisan test

and you will get:

php_1  |    RUNS  Tests\Unit\ExampleTest
php_1  |   • basic test
php_1  |
php_1  |   Tests:  2 pending
php_1  |
php_1  |    PASS  Tests\Unit\ExampleTest
php_1  |   ✓ basic test
php_1  |
php_1  |    RUNS  Tests\Feature\ExampleTest
php_1  |   • basic test
php_1  |
php_1  |   Tests:  1 passed, 1 pending
php_1  | "docker"
php_1 exited with code 1

Application environment is set to a "docker" which was passed with docker --env argument. However, the expected behavior and response is "testing".

This test demonstrates that env variables from a phpunit.xml are not loaded or are overrode, therefore, the DB_CONNECTION and DB_DATABASE will also be overridden by docker --env.

This issue leads to a complete database erase if you are using a RefreshDatabase trait because usingInMemoryDatabase() will return false and than refreshTestDatabase() will call a migrate:fresh...