Welcome Guest, Not a member yet? Register   Sign In
Running automated tests with mysql database possible?
#1

After successful deployment I am now trying to add testing to my project and I require a couple of tables in the mysql database. The tests shipped with the CI4 distro all use sqlite3 memory-based database and I have tried adopt the tests for mysql.
I have setup migrations for the tables I need and some seed files as well. They seems to be working when running in the 

I have stumbled over a couple of things I don't understand and wonder if someone could shed some light:
1) If I set $refresh = true in my extended DatabaseTestCase class, the setup with migration and seeds are run before every single test in the file, time consuming. However, setting $refresh = false doesn't run the migrations but runs the seeds so the tables are not setup and possibly key collisions when running the same seed again. 
With $refresh = false - how should I run the migrations to setup the test database?

2) Took me some time to find the overridden envs in phpunit.xml.dist to use sqlite3. 
Why are they there?

Thanks,
/Mattias
Reply
#2

(03-01-2020, 02:06 AM)tgix Wrote: 2) Took me some time to find the overridden envs in phpunit.xml.dist to use sqlite3. 
Why are they there?

Are you asking, "Why use sqlite3?"

Your experience should provide the answer, it's not as "time consuming".

Unit testing database code is a bear. You really don't have a choice on refreshing for every test. It has to be done or you cannot trust the state of the db when it comes time to assert something.

This page is old PHP Unit documentation, but it's still informative. The same page doesn't exist in the docs for version 8.5, the version CI v4 uses. I'm not sure why.
Reply
#3

Have you ever been able to run the tests against the test database?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB