lundi 29 avril 2019

Laravel testbench migration order

I'm trying to create a migration test with Testbench and I'm having trouble setting up migrations.

The test is for api responses of a package I created. This package in return depends on another package with migrations with are not published but are using loadMigrationsFrom() method in ServiceProvider.

This other package is creating tables and new column in users table. Now, in an actual Laravel app there is no problem since I guess it orders all migrations based on a date but when running a test I get an error saying users table does not exist.

Only solution I can think of is just publishing migrations from other package but I'd like to avoid that. Is there any other way?

I'm using DatabaseMigrations trait but I changed it to:

use DatabaseMigrations {
    runDatabaseMigrations as public parentRunDatabaseMigrations;
}    

public function runDatabaseMigrations()
{
    $this->app->afterResolving(
        function ($migrator) {
            $migrator->path(__DIR__.'/../../vendor/test/my-package/database/migrations');
        }
    );

    $this->parentRunDatabaseMigrations();
}

Aucun commentaire:

Enregistrer un commentaire