Skip to content

Commit

Permalink
Add before/after database truncation methods to DatabaseTruncation tr…
Browse files Browse the repository at this point in the history
…ait (#48345)
  • Loading branch information
cwilby committed Sep 11, 2023
1 parent b8b2d9e commit ba44e0b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Illuminate/Foundation/Testing/DatabaseTruncation.php
Expand Up @@ -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());
Expand All @@ -45,6 +47,8 @@ protected function truncateDatabaseTables(): void
// Use the default seeder class...
$this->artisan('db:seed');
}

$this->afterTruncatingDatabase();
}

/**
Expand Down Expand Up @@ -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
{
//
}
}

0 comments on commit ba44e0b

Please sign in to comment.