Skip to content

Commit 1e03a4a

Browse files
authored
[10.x] Streamline DatabaseMigrations and RefreshDatabase events (#49153)
* [10.x] Test Improvements Use available method from `RefreshDatabase::afterRefreshingDatabase()` Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 77da0a7 commit 1e03a4a

File tree

76 files changed

+110
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+110
-78
lines changed

src/Illuminate/Foundation/Testing/DatabaseMigrations.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,46 @@ trait DatabaseMigrations
1616
*/
1717
public function runDatabaseMigrations()
1818
{
19-
$this->artisan('migrate:fresh', $this->migrateFreshUsing());
20-
21-
$this->app[Kernel::class]->setArtisan(null);
19+
$this->beforeRefreshingDatabase();
20+
$this->refreshTestDatabase();
21+
$this->afterRefreshingDatabase();
2222

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

2626
RefreshDatabaseState::$migrated = false;
2727
});
2828
}
29+
30+
/**
31+
* Refresh a conventional test database.
32+
*
33+
* @return void
34+
*/
35+
protected function refreshTestDatabase()
36+
{
37+
$this->artisan('migrate:fresh', $this->migrateFreshUsing());
38+
39+
$this->app[Kernel::class]->setArtisan(null);
40+
}
41+
42+
/**
43+
* Perform any work that should take place before the database has started refreshing.
44+
*
45+
* @return void
46+
*/
47+
protected function beforeRefreshingDatabase()
48+
{
49+
// ...
50+
}
51+
52+
/**
53+
* Perform any work that should take place once the database has finished refreshing.
54+
*
55+
* @return void
56+
*/
57+
protected function afterRefreshingDatabase()
58+
{
59+
// ...
60+
}
2961
}

tests/Integration/Database/DatabaseCustomCastsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class DatabaseCustomCastsTest extends DatabaseTestCase
1515
{
16-
protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
16+
protected function afterRefreshingDatabase()
1717
{
1818
Schema::create('test_eloquent_model_with_custom_casts', function (Blueprint $table) {
1919
$table->increments('id');

tests/Integration/Database/DatabaseEloquentBroadcastingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class DatabaseEloquentBroadcastingTest extends DatabaseTestCase
2020
{
21-
protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
21+
protected function afterRefreshingDatabase()
2222
{
2323
Schema::create('test_eloquent_broadcasting_users', function (Blueprint $table) {
2424
$table->increments('id');

tests/Integration/Database/DatabaseEloquentModelAttributeCastingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class DatabaseEloquentModelAttributeCastingTest extends DatabaseTestCase
1414
{
15-
protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
15+
protected function afterRefreshingDatabase()
1616
{
1717
Schema::create('test_eloquent_model_with_custom_casts', function (Blueprint $table) {
1818
$table->increments('id');

tests/Integration/Database/DatabaseEloquentModelCustomCastingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class DatabaseEloquentModelCustomCastingTest extends DatabaseTestCase
1818
{
19-
protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
19+
protected function afterRefreshingDatabase()
2020
{
2121
Schema::create('test_eloquent_model_with_custom_casts', function (Blueprint $table) {
2222
$table->increments('id');

tests/Integration/Database/EloquentAggregateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class EloquentAggregateTest extends DatabaseTestCase
1010
{
11-
protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
11+
protected function afterRefreshingDatabase()
1212
{
1313
Schema::create('users', function (Blueprint $table) {
1414
$table->increments('id');

tests/Integration/Database/EloquentBelongsToManyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function tearDown(): void
2222
Carbon::setTestNow(null);
2323
}
2424

25-
protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
25+
protected function afterRefreshingDatabase()
2626
{
2727
Schema::create('users', function (Blueprint $table) {
2828
$table->increments('id');

tests/Integration/Database/EloquentBelongsToTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class EloquentBelongsToTest extends DatabaseTestCase
1212
{
13-
protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
13+
protected function afterRefreshingDatabase()
1414
{
1515
Schema::create('users', function (Blueprint $table) {
1616
$table->increments('id');

tests/Integration/Database/EloquentCollectionFreshTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class EloquentCollectionFreshTest extends DatabaseTestCase
1111
{
12-
protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
12+
protected function afterRefreshingDatabase()
1313
{
1414
Schema::create('users', function (Blueprint $table) {
1515
$table->increments('id');

tests/Integration/Database/EloquentCollectionLoadCountTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class EloquentCollectionLoadCountTest extends DatabaseTestCase
1414
{
15-
protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
15+
protected function afterRefreshingDatabase()
1616
{
1717
Schema::create('posts', function (Blueprint $table) {
1818
$table->increments('id');

0 commit comments

Comments
 (0)