'Using Phpunit/ Why phpunit removes all data in my database

I'm trying to test my functions but everytime I try to run phpunit, it will delete all the records in my tables. I already setup my phpunit.xml file, to just in my test database, I just followed everything in the docs, do I have to setup a sqlite inmy machine, since I don't have that ? or what ? I only have laragon installed and phpmyadmin.

phpunit.xml file

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
   backupStaticAttributes="false"
   bootstrap="vendor/autoload.php"
   colors="true"
   convertErrorsToExceptions="true"
   convertNoticesToExceptions="true"
   convertWarningsToExceptions="true"
   processIsolation="false"
   stopOnFailure="false">
   <testsuites>
    <testsuite name="Feature">
        <directory suffix="Test.php">./tests/Feature</directory>
    </testsuite>

    <testsuite name="Unit">
        <directory suffix="Test.php">./tests/Unit</directory>
    </testsuite>
</testsuites>
<filter>
    <whitelist processUncoveredFilesFromWhitelist="true">
        <directory suffix=".php">./app</directory>
    </whitelist>
</filter>
<php>
    <env name="APP_ENV" value="testing"/>
    <env name="CACHE_DRIVER" value="array"/> 
    <env name="SESSION_DRIVER" value="array"/>
    <env name="QUEUE_DRIVER" value="sync"/>
    <env name="DB_CONNECTION" value="sqlite"/>
    <env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>


Solution 1:[1]

Be sure to use the DatabaseMigrations trait in your test classes. Eg.

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\RefreshDatabase;

class SomeTest extends TestCase
{
     use DatabaseMigrations;
     use RegreshDatabase;

   /**
    * A basic test example.
    *
    * @return void
    */
    public function testSomething()
    {
        //some code
    }
        
}

This migrates your data on setup, and then registers a direction to roll back the migrations when the application is torn down at the end of the test.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1