Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sam's avatar
Level 4

php artisan test - environment

Hi folks,

Just wondering if anyone know if using php artisan test actually uses the phpunit.xml file or a .env.testing file at all please?

Regards,

0 likes
11 replies
Sam's avatar
Level 4

Thanks @sergiu17, indeed it looks like it does but it doesn't seem to take note of my Database settings in here :/

Sinnbeck's avatar

What isnt working? A specific model that uses the wrong connection ? Be aware that if you have set it manually on the model, it ignores phpunit.xml/env

Sam's avatar
Level 4

Hi @sinnbeck ,

So i have set:

     <server name="DB_CONNECTION" value="sqlite"/>
     <server name="DB_DATABASE" value=":memory:"/>

When running phpunit natively /vendor/bin/phpunit then these variables are picked up. When i run php artisan test, it isn't I can see it's reading from my .env file?

Sam's avatar
Level 4

The above variables are set in the phpunit.xml file as per the docs

The testing environment variables may be configured in the phpunit.xml file, but

Sinnbeck's avatar

it isn't I can see it's reading from my .env file?

And I asked

What env file?

Sam's avatar
Level 4

Sorry, I can see it is reading from .env

Sinnbeck's avatar

No worries. Ok so you dont have a .env.testing file? :) If so it will also use this file.

Sam's avatar
Level 4

Nope, no .env.testing file at all, I just figured I could use the phpunit.xml rather than having another .env file laying around. Like I said, PHPUnit itself picks up the database config but php artisan test just defaults to the .env which I found a little weird.

shez1983's avatar

so whats the point of the .env.test file? is it used ANYWHERE anymore?

Please or to participate in this conversation.