vincent15000's avatar

sail test / sail artisan test

Hello,

Something strange ... since today, when I run sail test or sail artisan test, the database used for testing is the main database and not the testing one.

I have checked the configuration in the phpunit.xml file, all seems to be good.

<php>
    <env name="APP_ENV" value="testing"/>
    <env name="APP_MAINTENANCE_DRIVER" value="file"/>
    <env name="BCRYPT_ROUNDS" value="4"/>
    <env name="CACHE_STORE" value="array"/>
    <env name="DB_DATABASE" value="testing"/>
    <env name="MAIL_MAILER" value="array"/>
    <env name="PULSE_ENABLED" value="false"/>
    <env name="QUEUE_CONNECTION" value="sync"/>
    <env name="SESSION_DRIVER" value="array"/>
    <env name="TELESCOPE_ENABLED" value="false"/>
</php>

And I have the .env.testing file with these keys.

APP_ENV=testing
...
DB_DATABASE=testing
...

Why could the application suddenly use the main database instead of the testing one ?

Do you have any suggestion ?

Thanks for your help.

V

0 likes
4 replies
s4muel's avatar

probably not your case, but do you run the command directly? something similar occurred to me when i created a custom command that (among other things) run the parallel tests as a Process. in that case the threads of the test command inherited the env from the main command (not taking phpunit/testing env into account) and messed up the things a bit. i fixed that by explicitely setting the env variables in the main command (https://laravel.com/docs/11.x/processes#environment-variables).

as i said, probably not your case, but might ring some bells

1 like
vincent15000's avatar

@s4muel Effectively that's not my case. But it lets me think about something. ;)

1 like

Please or to participate in this conversation.