I'm building my DB test in memory and I need to make migrations run before running tests The problem is I have this tests in one microservice and migrations in another So I need something like:
class MyTest extends TestCase
{
use RefreshDatabase;
public function setUp(): void
{
parent::setUp();
$path = str_replace('api', 'admin', base_path()) . '/database/migrations/';
Artisan::call('migrate', ['--path' => $path]);
}
public functions myFunction()
{
}
}
I tried to run:
$path = str_replace('api', 'admin', base_path()) . '/database/migrations/';
echo PHP_EOL . $path . PHP_EOL;
Artisan::call('migrate', ['--path' => $path]);
Where 'api' is one project and 'admin' is another one
But it did not work out. Also some other combinations of the migration path did not work out I have two services on my PC running in vagrant and working fine I just can't find a way how to build a command that will call migrations from one service to another So...how do I do this? Maybe I'm missing something?
In order you've faced the same issue when your project is divided into few Laravel microservices and migrations leave in one of them but your test is in another one here is few choices up to you:
Symlink. Yes. Just create a symlink to migrations from one sub project to another one. We didn't really used it in practice but it might be a way
The solution we did: just create a sepparate DB not in memory(is it even usefull?), then use once the command:
php artisan migrate --database=db_for_test_name
And in DB tests then add DatabaseTransactions that locks the state of you test DB before tests and bring it back after test worked no matter failed it or not. It will help you save migration history in migration table and rerun the command above when you have new migrations