From 41ddc98ca17de564305c5421a7c6a1fd92f6d08f Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 28 Nov 2023 09:47:25 +0800 Subject: [PATCH] wip Signed-off-by: Mior Muhammad Zaki --- .../Foundation/Testing/DatabaseMigrations.php | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/DatabaseMigrations.php b/src/Illuminate/Foundation/Testing/DatabaseMigrations.php index 10a3a7300af6..4301c24ad473 100644 --- a/src/Illuminate/Foundation/Testing/DatabaseMigrations.php +++ b/src/Illuminate/Foundation/Testing/DatabaseMigrations.php @@ -16,9 +16,9 @@ trait DatabaseMigrations */ public function runDatabaseMigrations() { - $this->artisan('migrate:fresh', $this->migrateFreshUsing()); - - $this->app[Kernel::class]->setArtisan(null); + $this->beforeRefreshingDatabase(); + $this->refreshTestDatabase(); + $this->afterRefreshingDatabase(); $this->beforeApplicationDestroyed(function () { $this->artisan('migrate:rollback'); @@ -26,4 +26,36 @@ public function runDatabaseMigrations() RefreshDatabaseState::$migrated = false; }); } + + /** + * Refresh a conventional test database. + * + * @return void + */ + protected function refreshTestDatabase() + { + $this->artisan('migrate:fresh', $this->migrateFreshUsing()); + + $this->app[Kernel::class]->setArtisan(null); + } + + /** + * Perform any work that should take place before the database has started refreshing. + * + * @return void + */ + protected function beforeRefreshingDatabase() + { + // ... + } + + /** + * Perform any work that should take place once the database has finished refreshing. + * + * @return void + */ + protected function afterRefreshingDatabase() + { + // ... + } }