We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Unit test - Run migrations on in memory DB

Hey there,

to test the models it seems like I need a working DB connection and as I don't want to have a local mysql db but rather a clean db for each execution I thought of using in memory db. Phalcon only supports adapters for mysql, postgres and sqlite which means I would use sqlite with dbname :memory:. No I thought I could execute the db migration on my in memory db before running the tests. But unfortunately I can't pass an open connection to the migrations but just the configuration. Anyone has an idea how I can open a sqlite3 in memory db and run the migrations? Alternatives for a proper test setup to test models etc would be welcome as well :)

Thanks in advance

edited May '20

The trouble with changing the RDBMS for tests is that it might not catch some errors, or will generate new ones that happen due to changing SQL dialects.

My suggestion would be to duplicate your database structure into a test database. Then as part of your setup for your tests, you change the database connection from your main database, to your test database.