Unable to get testing to use a testing database sqlite L5.5

Posted 1 year ago by longestdrive

I thought I had this set up cracked but I haven't. It seems no matter what I do I'm unable to get my tests to use an sqlite database to use for tests and instead keeps going to my default mysql database.

I think I've done everything as suggested in all the threads and tutorials but absolutely no luck in Laravel 5.5

In my database config I have:

'default' => env('DB_CONNECTION', 'mysql'),


'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],
        'sqlite_testing_memory' => [
            'driver' => 'sqlite',
            'database' => ':memory:',
            'prefix' => '',
        ],
        'sqlite_testing' => [
            'driver' => 'sqlite',
            'database' => database_path('database.sqlite'),
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

In my Phpunit.xml I have the following:

<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_testing"/>
        <env name="DB_DEFAULT" value="sqlite_testing" />
        <env name="DB_DATABASE" value="/database/database.sqlite"/>
    </php>

I have a file - database.sqlite in my database directory

I also tried placing that file in the storage folder and changed the path to the storage folder but still didnt work.

So - what's wrong with my set up and how can I check before my tests run which database it's using?

Thanks

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.