Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Illuminate/Support/Facades/ParallelTesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
* @method static void resolveTokenUsing(\Closure|null $resolver)
* @method static void setUpProcess(callable $callback)
* @method static void setUpTestCase(callable $callback)
* @method static void setUpTestDatabasePreMigration(callable $callback)
* @method static void setUpTestDatabase(callable $callback)
* @method static void tearDownProcess(callable $callback)
* @method static void tearDownTestCase(callable $callback)
* @method static void callSetUpProcessCallbacks()
* @method static void callSetUpTestCaseCallbacks(\Illuminate\Foundation\Testing\TestCase $testCase)
* @method static void callSetUpTestDatabasePreMigrationCallbacks(string $database)
* @method static void callSetUpTestDatabaseCallbacks(string $database)
* @method static void callTearDownProcessCallbacks()
* @method static void callTearDownTestCaseCallbacks(\Illuminate\Foundation\Testing\TestCase $testCase)
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Testing/Concerns/TestDatabases.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ protected function bootTestDatabase()

$this->switchToDatabase($testDatabase);

if ($created) {
ParallelTesting::callSetUpTestDatabasePreMigrationCallbacks($testDatabase);
}

if (isset($uses[Testing\DatabaseTransactions::class])) {
$this->ensureSchemaIsUpToDate();
}
Expand Down
36 changes: 36 additions & 0 deletions src/Illuminate/Testing/ParallelTesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class ParallelTesting
*/
protected $setUpTestCaseCallbacks = [];

/**
* All of the registered "setUp" test database callbacks prior the migrations.
*
* @var array
*/
protected $setUpTestDatabasePreMigrationCallbacks = [];

/**
* All of the registered "setUp" test database callbacks.
*
Expand Down Expand Up @@ -117,6 +124,17 @@ public function setUpTestCase($callback)
$this->setUpTestCaseCallbacks[] = $callback;
}

/**
* Register a "setUp" test database prior the migration callback.
*
* @param callable $callback
* @return void
*/
public function setUpTestDatabasePreMigration($callback)
{
$this->setUpTestDatabasePreMigrationCallbacks[] = $callback;
}

/**
* Register a "setUp" test database callback.
*
Expand Down Expand Up @@ -184,6 +202,24 @@ public function callSetUpTestCaseCallbacks($testCase)
});
}

/**
* Call all of the "setUp" test database callbacks.
*
* @param string $database
* @return void
*/
public function callSetUpTestDatabasePreMigrationCallbacks($database)
{
$this->whenRunningInParallel(function () use ($database) {
foreach ($this->setUpTestDatabasePreMigrationCallbacks as $callback) {
$this->container->call($callback, [
'database' => $database,
'token' => $this->token(),
]);
}
});
}

/**
* Call all of the "setUp" test database callbacks.
*
Expand Down
1 change: 1 addition & 0 deletions tests/Testing/ParallelTestingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public static function callbacks()
['setUpProcess'],
['setUpTestCase'],
['setUpTestDatabase'],
['setUpTestDatabasePreMigration'],
['tearDownTestCase'],
['tearDownProcess'],
];
Expand Down