[13.x] Add `WithoutMigrationEvents` attribute

Merged
XU
9d ago
+188-1

With LazilyRefreshDatabase, migrations run on the first query inside the test, so any DB::listen() or expectsDatabaseQueryCount() registered by that test also sees every migrate:fresh query.

class UserTest extends TestCase
{
    use LazilyRefreshDatabase;

    #[WithoutMigrationEvents]
    public function test_it_runs_one_query()
    {
        $this->expectsDatabaseQueryCount(1);

        User::first();
    }
}

Without the attribute, this fails when the test runs first (alone, with --filter, or in a parallel worker) and passes when another test migrated before it.