Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set DB_CONNECTION to use sqlite in-memory database when testing

#Set DB_CONNECTION to use sqlite in-memory database when testing

  • Open `phpunit.xml' file in the current project
  • Add the following environment variables to the appropriate section
  <env name="DB_CONNECTION" value="sqlite">
  <env name="DB_DATABASE" value=":memory:">
  • in config\database.php file, change the default sqlite connection to
  'connections' => [
    'driver'   => 'sqlite',
    'database' => env('DB_DATABASE', database_path('database.sqlite')),
    'prefix'   => '',
  ],
@maxalmonte14

This comment has been minimized.

Copy link

@maxalmonte14 maxalmonte14 commented Oct 31, 2018

I think the environment tags in the phpunit.xml file should autoclose, otherwise, you're going to receive some sort of error like the following

Could not load "/some/fake/directory/phpunit.xml".

Opening and ending tag mismatch: env line 34 and php

Opening and ending tag mismatch: env line 33 and phpunit

Premature end of data in tag php line 25

Premature end of data in tag phpunit line 2

No problem when you add the / character to close the tags

<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment