This article covers How to Use Sqlite File database with Laravel Dusk Testing. Sqlite is pretty easy to use and does not require a database server on your development environment.

Start off by creating a separate environment for your Laravel Dusk Tests.

The configuration properties for your web application resides in .env file which is in application's root folder, create a separate property configuration file for your dusk tests by creating another environment file with name .env.dusk.{environment}, where environment is the name your application environment.

You can now change the Db connection properties in the dusk environment file.

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=
DB_USERNAME=root
DB_PASSWORD=

Next, Now create a new file with name database.sqlite inside your database folder. This file will be used by sqlite to create your tables and put data into.

If you are already using sqlite with your development environment and want to use a different sqlite database for your dusk. Then you can add a separate configuration in your database config file.

Open database.php file located at app > config directory.

Add a new entry inside connections array

'sqlite_testing' => [
    'driver'   => 'sqlite',
    'database' => database_path('sqlite.testing.database'),
    'prefix'   => '',
],

Now you can use this configuration in your dusk environment file.

DB_CONNECTION=sqlite_testing
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=
DB_USERNAME=root
DB_PASSWORD=

Also you need to create sqlite.testing.database file in your database directory.

Since your sqlite database is currently empty it's good idea to run DatabaseMigrations manually, or before each test.

Next up, Learn how to Login and Logout Users using Dusk methods.

Comments