Hi all, so I'm trying to set up testing for my project part-way through (cause I was silly and didn't write tests from the start...
I'll give a quick summary of the project so there is some context...
- A community runs a game server, which uses a database for in-game persistence, logs, and other data.
- I'm writing a utility site so that users can view their in-game character information, admins can view logs, edit players, write private notes etc, all on a web interface
- This means I have two databases for the site: the game database, which is controlled by the game server and the website simply accesses to read and edit content ... and the website database, which is controlled by the website and its migrations, and only the website accesses.
So the website database has a relationship join to the game database from users...
- A user logs into the website using steam auth and their steamid and login tokens etc are saved on the website database
- A player joins the game and the game stores their steam ID in the game database
- the user entry in the website database is linked one-to-one to the game database player entry based on their steam IDs
I have a local copy of the game database I use for development. Changes to the data won't affect anything live.
Anyway, I hope that sort of makes sense... Onto the question...
My issue is when I want to test my application with these databases...
The Website Database is easy enough, regardless of if I use an SQLite :memory: database or a physical database, I can just use the RefreshDatabase trait and PHPUnit/etc will handle refreshing the database with my migrations for it... all good... no problem there as far as I am aware...
The issue comes when I want to have the second (game) database change rollback handled with testing...
I don't have migrations for this database, as it's not controlled or managed by the website.
My questions are:
-
How can I have PHPUnit/cypress/etc reset changes to the second database (the game database) caused by automated tests?
-
If I have to write migrations for #1 to be doable, how can I tell a migration to only run when the app environment is testing? (i.e. any migration for the game database must NOT run when running art migrate in a production or local environment)
Hopefully all this rambling makes sense, and I'll try to elaborate if anything needs clarification.
It's quite possible I'm missing something obvious here.
(Crossposted https://stackoverflow.com/questions/68226933/phpunit-cypress-testing-2-databases-in-laravel )