mercredi 25 novembre 2020

PHP Laravel SQLite for both testing and as actual database

I want to use Sqlite driver for both test database and as actual database. My .env file is:

DB_CONNECTION=sqlite

It's okay, i can use sqlite for actual database and for testing i defined something like this under my connections array in config/database.php:

'testing' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('test.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

        'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

My phpunit.xml configuration is also like:

<php>
      <server name="APP_ENV" value="testing"/>
      <server name="BCRYPT_ROUNDS" value="4"/>
      <server name="CACHE_DRIVER" value="array"/>
      <server name="DB_CONNECTION" value="testing"/>
      <server name="DB_DATABASE" value=":memory:"/>
      <server name="MAIL_MAILER" value="array"/>
      <server name="QUEUE_CONNECTION" value="sync"/>
      <server name="SESSION_DRIVER" value="array"/>
      <server name="TELESCOPE_ENABLED" value="false"/>
</php>

Yet it still uses my actual database for testing, i tried configure both database.php and phpunit.xml with different ways in the internet but it still not working.

Examples was like using mysql as actual and sqlite for testing, but i want to use sqlite for both of them.

Aucun commentaire:

Enregistrer un commentaire