oes's avatar
Level 3

Sqlite for testing

Hey Folks.

I have a lumen app setup with eloquent with the the norm mysql database settings. But of course for testing I don't want to use mysql but sqlite.

Within phpunit.xml I added the DB_DRIVER as sqlite and a whole load of other options but I cannot get a test to run with 'DatabaseMigrations'

Example phpuntit

    <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_DRIVER" value="sqlite" />
        <env name="DB_DATABASE" value=":memory:" />
    <!--<env name="DB_DATABASE" value="database.sqlite" />-->
    </php>

I just keep getting error etc...

PDOException: SQLSTATE[HY000] [1049] Unknown database 'database.sqlite'

Am I missing something?

0 likes
1 reply
tykus's avatar

The relevant key for the database server is DB_CONNECTION, not DB_DRIVER:

// config/database.php
'default' => env('DB_CONNECTION', 'mysql'),

So, your .env should read

<env name="DB_CONNECTION" value="sqlite" />

Next, in the config file, there is already a default value for a SQLite database

'database' => env('DB_DATABASE', database_path('database.sqlite')),

Note that it is located within the database_path() which is {PROJECT_ROOT}/database/database.sqlite, however, you have just given database.sqlite and presumably there is not such file in the project root

Please or to participate in this conversation.