From ba44e0b2cb60bc4000d751756a461e0f25534966 Mon Sep 17 00:00:00 2001 From: Cameron Wilby Date: Mon, 11 Sep 2023 07:28:36 -0700 Subject: [PATCH] Add before/after database truncation methods to DatabaseTruncation trait (#48345) --- .../Foundation/Testing/DatabaseTruncation.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Illuminate/Foundation/Testing/DatabaseTruncation.php b/src/Illuminate/Foundation/Testing/DatabaseTruncation.php index 811b56e20952..cea2d8d09250 100644 --- a/src/Illuminate/Foundation/Testing/DatabaseTruncation.php +++ b/src/Illuminate/Foundation/Testing/DatabaseTruncation.php @@ -24,6 +24,8 @@ trait DatabaseTruncation */ protected function truncateDatabaseTables(): void { + $this->beforeTruncatingDatabase(); + // Migrate and seed the database on first run... if (! RefreshDatabaseState::$migrated) { $this->artisan('migrate:fresh', $this->migrateFreshUsing()); @@ -45,6 +47,8 @@ protected function truncateDatabaseTables(): void // Use the default seeder class... $this->artisan('db:seed'); } + + $this->afterTruncatingDatabase(); } /** @@ -144,4 +148,24 @@ protected function exceptTables(?string $connectionName): array return [$this->app['config']->get('database.migrations')]; } + + /** + * Perform any work that should take place before the database has started truncating. + * + * @return void + */ + protected function beforeTruncatingDatabase(): void + { + // + } + + /** + * Perform any work that should take place once the database has finished truncating. + * + * @return void + */ + protected function afterTruncatingDatabase(): void + { + // + } }