testbench-dusk
testbench-dusk copied to clipboard
Published migrations are not being rollbacked on test teardown (`beforeApplicationDestroyed`)
- Testbench Version: 7.7
- Laravel Version: 9.*
- PHP Version: 8.1
- Database Driver & Version: sqlite
Description:
I am facing a strange issue like testbench-dusk cannot load testbench-dusk\laravel\database\migrations during rollback
I have used testbench-core for some tests, and it is working flawlessly, using memory sqlite So I continued to set up my visual tests but this time I should use a file sqlite db
I used the following setup for migrations
protected function defineDatabaseMigrations(): void
{
$this->loadLaravelMigrations(['--force'=>true]); // force flag, creates the database without any other scripts usage
$this->withoutMockingConsoleOutput();
$this->artisan(VendorPublishCommand::class, ['--tag' => 'my-package-config']);
// $this->loadMigrationsFrom(database_path('migrations'));
$this->artisan(InstallCommand::class); // A command that publish third party migrations on database dir (during test in orchestra-dusk\database\migrations\
$this->loadMigrationsFrom(__DIR__ . '/Database/Migrations'); // load test migrations
}
The result of my test db migrations was
| migration name | scope | path | batch |
|---|---|---|---|
| users_2014 | laravel | testbench-dusk\laravel\migrations | 1 |
| passwords_2014 | laravel | testbench-dusk\laravel\migrations | 1 |
| fortify_migrations_2014 | published | testbench-dusk\laravel\database\migrations | 2 |
| third_package_migrations | published | testbench-dusk\laravel\database\migrations | 2 |
| third_no2_package_migrations | published | testbench-dusk\laravel\database\migrations | 2 |
| test_migrations | test | myTestsDire\Database\Migrations | 3 |
| test_migrations | test | myTestsDire\Database\Migrations | 3 |
As I was repeating my tests again and again, I found out that the rollback didn't work as expected as it was trying to find the published migration files but the main database\migrations path (batch No2) wasn't loaded on Migrator
So it was starting rollback, but every time was stopping silently on the second batch as it couldn't resolve them
As a result I had some errors of double seeding etc
Steps To Reproduce:
- load laravel migrations
- publish some migrations during test
- load some test migrations
- check your db.sqlite file after test. It will have stop rollback on the pulished migrations
Workaround
Add this line forcing migrator to load the path
$this->loadMigrationsFrom(database_path('migrations'));
Can you submit a failing tests for this
You may find one here
https://github.com/orchestral/testbench-dusk/compare/7.x...GeoSot:testbench-dusk:test-default-databases
But at least in that case it ignores to migrate it too. In my case for some reason, it ignores it only during rollback