Hi, I am trying to seed an sqlite in-memory database for use in phpunit tests. in tests/TestCase.php I have a prepareForTests() method with two artisan calls:
protected function prepareForTests()
{
Artisan::call('migrate');
Artisan::call('db:seed');
}
The call to db:seed seems to be causing this error:
PDOException: SQLSTATE[HY000]: General error: 1 near "SET": syntax error
I think this was caused by a difference between sqlite and mysql syntax when disabling foreign keys.
Before each seed is executed I am turning off the foreign key checks with:
DB::statement('SET FOREIGN_KEY_CHECKS = 0');
This works fine when using mysql, however the sqlite documentation uses a different syntax: https://www.sqlite.org/foreignkeys.html#fk_enable so I guess I have a couple of options - somehow check which engine is running then run the specific statement for that engine, write separate seeder files, or just use mysql as the test db.
Are there any other options? What would you choose?