jeudi 29 mars 2018

laravel testing requires multiple databases trying to use sqlite duplicate tables

My testing journey continues...

In an app I have multiple databases 1. which is for the backend content with users for the back end and other stuff 2. the front end and users for the front end.

To carry out a test I need to create a user for the front end and test against content in the backend.

I'm trying to configure Phpunit and laravel to use two databases in memory using sqlite and I'm struggling.

I have two migration files for each database and have my normal set up as follows in database.php

'sqlite_testing_memory' => [
        'driver' => 'sqlite',
        'database' => ':memory:',
        'prefix' => '',
    ],

in my phpunit.xml I have created the following:

    <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_memory"/>
    <env name="DB_DEFAULT" value="sqlite_testing_memory" />
    <env name="DB_DATABASE" value=":memory:"/>
    <env name="DB_DATABASE_2" value=":memory:"/>

Each time I try and migrate the databases I get conflicts due to tables already existing e.g users from the back end conflicting with users from the front end.

I understand I can use Schema::connection->('connection_name') to specify the connection in the migration file but still get the conflicts.

Is it possible to have multiple databases in an sqlite in memory.

How can I get my tests to use multiple databases or should I consider reverting to a mysql testing database?

Help appreciated

Aucun commentaire:

Enregistrer un commentaire