Skip to content
Merged
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 setUpTestDatabaseBeforeMigrating(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 callSetUpTestDatabaseBeforeMigratingCallbacks(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::callSetUpTestDatabaseBeforeMigratingCallbacks($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 to the migrations.
*
* @var array
*/
protected $setUpTestDatabaseBeforeMigratingCallbacks = [];

/**
* 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 callback that runs prior to the migrations.
*
* @param callable $callback
* @return void
*/
public function setUpTestDatabaseBeforeMigrating($callback)
{
$this->setUpTestDatabaseBeforeMigratingCallbacks[] = $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 that run prior to migrations.
*
* @param string $database
* @return void
*/
public function callSetUpTestDatabaseBeforeMigratingCallbacks($database)
{
$this->whenRunningInParallel(function () use ($database) {
foreach ($this->setUpTestDatabaseBeforeMigratingCallbacks 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'],
['setUpTestDatabaseBeforeMigrating'],
['tearDownTestCase'],
['tearDownProcess'],
];
Expand Down
Loading