Okay, I figured out a reasonable workaround:
- Create test versions of each database. They have to use the same database driver (eg. MySQL) as your real databases.
- In your
phpunit.xmlfile, add antag for each database, overriding the environment variables for each. It may be that you will need to change username and password for test databases too, but I left them the same so didn't need to override any more environment variables. - Use the DatabaseMigrations trait in your tests.
Example phpunit.xml
…
<env name="DB_ACCOUNT_DATABASE" value="accounts_test"/>
<env name="DB_SITE_DATABASE" value="site_test"/>
…
Now you can run normal local databases that can change over time, and test databases that are only used by phpunit with Faker entries (for example)