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

faraz73's avatar

Only use sqlite in tests

Hi, i just wondering ... is there any way to put some code into our test to grantee our tests using sqlite, if it dose not, tests must not run. i want our tests, only runs on sqlite.

0 likes
4 replies
kevinbui's avatar

You don't have to do so. As long as you specify the DB_CONNECTION setting to be sqlite in the phpunit.xml file, your test cases are gonna use sqlite.

faraz73's avatar

@kevinbui I have write this code in setUp() ... why it returns null ??

public function setUp(): void
  {
    parent::setUp();

    $this->repo = resolve(StorageRepository::class);

    dd(config('DB_CONNECTION')); // returns null

    if(config('DB_CONNECTION') == 'mysql'){
      dd('The DBMS is Not sqlite, please set your phpunit.xml to sqlite and in memory database to run the tests');
    }
  }
tykus's avatar

@faraz73 there is most likely no config key named DB_CONNECTION - that is the environment variable name.

The config key would be config('database.default')

1 like
faraz73's avatar

@tykus oh .. i see that's env file .. how to get using database driver in tests ?

Please or to participate in this conversation.