laravel-useful-additions icon indicating copy to clipboard operation
laravel-useful-additions copied to clipboard

RefreshDatabaseFast fails after first run

Open stephenr85 opened this issue 1 year ago • 1 comments

In the DatabaseMigrations trait:

/**
     * Define hooks to migrate the database before and after each test.
     *
     * @return void
     */
    public function runDatabaseMigrations()
    {
        $this->beforeRefreshingDatabase();
        $this->refreshTestDatabase();
        $this->afterRefreshingDatabase();

        $this->beforeApplicationDestroyed(function () {
            $this->artisan('migrate:rollback');

            RefreshDatabaseState::$migrated = false;
        });
    }

The "migrate:rollback" call is basically reverting all of the fresh migration, so the second time the tests run, the checksum matches while the database is completely empty.

Not sure if this is due to a code update, or if there's a best practices way of avoiding this.

For now, I've overridden the runDatabaseMigrations method to remove the rollback command.

stephenr85 avatar May 07 '24 18:05 stephenr85

@stephenr85 would be awesome if you could send a PR with the fix!

Sairahcaz avatar Jul 15 '24 10:07 Sairahcaz