Why you should Enable DB_CONNECTION and DB_DATABASE in the phpunit.xml in Laravel
I'm going to give you my reasons why you should enable: env name="DB_CONNECTION" value="sqlite"/ env name="DB_DATABASE" value=":memory:"/ To specify a separate database and run in-memory queries for unit tests.
I wanted to explain to you the importance of why we have to configure a database at the time of development or for the testing environment. By default, I have this data:
Usually unit tests must be carried out in a test database, other than the development one and much less the production one. For now, we have been using the database that we use in development, so all the operations performed Because the tests persist in the same and with this, we do not have a controlled environment to do the tests, to establish a parallel database to do the tests we must make a configuration from the following file:
phpunit.xml
***
<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_CONNECTION" value="sqlite"/> -->
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<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>
***
Here you can customize the database to be used, in this example, SQLite (DB_DATABASE) and make it in-memory (DB_CONNECTION), which means that database operations will be performed in an in-memory database and not doing read/write operations on the database.
Note that it is using our development database here and what would happen if we run it again it will basically eliminate the ENTIRE development database. To avoid this, we must activate the database for testing and in memory so that the Operations are simulated in memory and not performed in the database and with this, they are faster:
***
<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_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<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>
***
- Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter