|
5 | 5 | use Facebook\WebDriver\Chrome\ChromeOptions; |
6 | 6 | use Facebook\WebDriver\Remote\DesiredCapabilities; |
7 | 7 | use Facebook\WebDriver\Remote\RemoteWebDriver; |
| 8 | +use Illuminate\Support\Facades\ParallelTesting; |
8 | 9 | use Laravel\Dusk\Browser as DuskBrowser; |
9 | 10 | use Laravel\Dusk\TestCase as DuskTestCase; |
10 | 11 |
|
11 | 12 | abstract class TestCase extends DuskTestCase |
12 | 13 | { |
| 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 | + |
13 | 20 | public static function startChromeDriver(array $arguments = []): void |
14 | 21 | { |
15 | 22 | parent::startChromeDriver(ParallelDriver::resolveDriverArguments($arguments)); |
16 | 23 | } |
17 | 24 |
|
| 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 | + |
18 | 44 | protected function newBrowser($driver): DuskBrowser |
19 | 45 | { |
20 | 46 | return new Browser($driver); |
|
0 commit comments