Laravel offers a ton of functionality, and every single option is not described in the documentation.
But hey, this is open source, so we can look at the code any time we want and see how things work.
I was working on a project recently that used multiple database connections, and only the default connection was getting refreshed when running tests.
Looking at the RefreshDatabase
trait, I saw that it checks for the presence of a $connectionsToTransact
property and uses that to determine which connections to refresh.
If not present, it falls back to the default connection.
So if I want to refresh multiple connections, it's a simple addition:
// tests/TestCase.php
abstract class TestCase extends BaseTestCase
{
use RefreshDatabase;
protected $connectionsToTransact = [
'connection1',
'connection2',
];
}
Here to help,
Joel
P.S. If you're a solo dev and don't have someone to do code review, I'd be happy to take a look. It's a really valuable process.