How to load migrations for a test from inside a package?

Using the standard Filament plugin service provider by Spatie where the migrations are stored in .php.stub without the timestamp prefix. But how do you load the migrations in order for testing? I don't want to duplicate them and have tried passing the exact file paths but this gives the error:
The "1" argument does not exist. at vendor/symfony/console/Input/ArrayInput.php:188
protected function defineDatabaseMigrations()
{
$this->loadLaravelMigrations();

$this->loadMigrationsFrom(__DIR__.'/database/migrations');

$this->loadMigrationsFrom(ExampleSystem::getMigrations(true));
}
protected function defineDatabaseMigrations()
{
$this->loadLaravelMigrations();

$this->loadMigrationsFrom(__DIR__.'/database/migrations');

$this->loadMigrationsFrom(ExampleSystem::getMigrations(true));
}
public function getMigrations($with_path = false): array
{
$migrations = [
'create_table1',
'create_table1',
];

if ($with_path) {
$path = realpath(__DIR__.'/../database/migrations');

array_walk($migrations, fn (&$migration) => $migration = "{$path}/{$migration}.php.stub" );
}

return $migrations;
}
public function getMigrations($with_path = false): array
{
$migrations = [
'create_table1',
'create_table1',
];

if ($with_path) {
$path = realpath(__DIR__.'/../database/migrations');

array_walk($migrations, fn (&$migration) => $migration = "{$path}/{$migration}.php.stub" );
}

return $migrations;
}
public function configurePackage(Package $package): void
{
$package
->name(self::$name)
->hasMigrations(ExampleSystem::getMigrations());
}
public function configurePackage(Package $package): void
{
$package
->name(self::$name)
->hasMigrations(ExampleSystem::getMigrations());
}
3 Replies
Dan Harrin
Dan Harrin2y ago
.php.stub files get copied over into your app, with a timestamp i dont know why youre using them directly? there should be a command that copies them and renames them to normal .php files
exactwebitesolutions
What's the correct procedure for migrating them into the test database? Do I need to manually copy them over each time to the tests/database/migrations folder and delete them afterwards?
toeknee
toeknee2y ago
In a test suite you would have already published them and it should be automated as part of your deployment
Want results from more Discord servers?
Add your server