Skip to content

Commit 059f086

Browse files
committed
Update TestCase.php
1 parent ed762bd commit 059f086

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/TestCase.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,42 @@
55
use Facebook\WebDriver\Chrome\ChromeOptions;
66
use Facebook\WebDriver\Remote\DesiredCapabilities;
77
use Facebook\WebDriver\Remote\RemoteWebDriver;
8+
use Illuminate\Support\Facades\ParallelTesting;
89
use Laravel\Dusk\Browser as DuskBrowser;
910
use Laravel\Dusk\TestCase as DuskTestCase;
1011

1112
abstract class TestCase extends DuskTestCase
1213
{
14+
/**
15+
* Tracks whether the per-process parallel setup has already been triggered for this worker.
16+
* Static so it persists across test instances within the same PHP process.
17+
*/
18+
protected static bool $parallelProcessSetUp = false;
19+
1320
public static function startChromeDriver(array $arguments = []): void
1421
{
1522
parent::startChromeDriver(ParallelDriver::resolveDriverArguments($arguments));
1623
}
1724

25+
/**
26+
* Refresh the application and, on the first test of each paratest worker, fire the
27+
* Laravel parallel-testing process callbacks (e.g. creating the per-worker database).
28+
*
29+
* paratest sets TEST_TOKEN per-worker but never calls callSetUpProcessCallbacks(),
30+
* so we do it here — once per process, after the app is booted so DB connections work.
31+
* The built-in setUpTestCase callbacks then switch the default connection to the
32+
* per-worker database, and any mirroring callbacks (e.g. for mysql-elevated) follow.
33+
*/
34+
protected function refreshApplication(): void
35+
{
36+
parent::refreshApplication();
37+
38+
if (ParallelDriver::runningInParallel() && ! static::$parallelProcessSetUp) {
39+
ParallelTesting::callSetUpProcessCallbacks();
40+
static::$parallelProcessSetUp = true;
41+
}
42+
}
43+
1844
protected function newBrowser($driver): DuskBrowser
1945
{
2046
return new Browser($driver);

0 commit comments

Comments
 (0)