Search code examples
mysqlsqlitelaravelbehatin-memory-database

Laravel 5 testing in memory


I am writing tests via behat for my large Laravel 5 project.

I have a testing copy of my MySQL database in MySQL and a seeder for that database that shares some of the seeders of other environments. All of that works as expected.

However, I tried switching to using a sqlite in-memory database because it would speed up my automated tests dramatically and because I'm running "artsian migrate:refresh ---seeder=TestDatabaseSeeder at the start of every behat scenario.

The problem I'm having is that some of my seed data causes sqlite to throw a very non-descript syntax error but MySQL is completely fine with the seed data.

Ideally, I think, I'd like to have it use MySQL in-memory for performance purposes and to keep the database engine consistent. Is there an easy way with or without Laravel to use MySQL in memory when running tests? A solution that does NOT involve duplicating & editing migration files in a way that makes sqlite happy?


Solution

  • It turned out that sqlite didn't like the way ' were being escaped.

    "\'" needed to be replaced with "''". And sqlite doesn't support enums so I changed out my migrations and use strings instead of enums.