I am trying to set up tests in Laravel, but I want to run different migrations from those that usually run.
The migrations that I run to initiate the database imports data from a production environment.
For testing I want to use a different database called "test", and I want to fill this test database with test data, not production data.
I added a "testing" connection to config/database.php which uses the "test" database:
'connections' => [
'mysql' => [
'database' => env('DB_DATABASE', 'forge'),
...
],
'testing' => [
'database' => 'test',
...
],
],
And I setup phpunit.xml to use this "testing" connection:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit ...>
...
<php>
<env name="DB_CONNECTION" value="testing"/>
...
</php>
</phpunit>
Now I want to initialize this "test" database with test data, using migrations from a different folder than the default.
I can use the normal migrations like this:
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
abstract class TestCase extends BaseTestCase
{
use DatabaseMigrations;
public function setUp(): void
{
parent::setUp();
$this->seed();
}
}
But this uses the default folder database/migrations.
I would like to put the testing migrations in folder tests/database/migrations.
Is there a way to let use DatabaseMigrations; use migrations from another folder?