首页 > 解决方案 > Laravel application and PHPUnit using sqlite, after executing the test database tables are dropped

问题描述

I'm creating a Laravel7 application.

Laravel application and PHPUnit are using sqlite as database.

For the development in my local I have configured as follows

// .env
DB_CONNECTION=sqlite
DB_DATABASE=/path/to/db.sqlite
// phpunit.xml
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>

Step 1: Register a new user and able to successfully login

Step 2: Execute the test and it executes successfully

Step 3: Again login to application but it shows SQLSTATE[HY000]: General error: 1 no such table: users (SQL: select * from "users" where "id" = 1 limit 1)

After executing the tests the existing tables are removed from the sqlite database even though the test's database is in memory

Note: In all my test classes I have use DatabaseMigrations; to include the trait.

How can I solve this issue?

标签: laravel-7

解决方案


推荐阅读