[ DatabaseTenancyBootstrapper::class, BatchTenancyBootstrapper::class, ], ]); Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class); }); test('batch repository is set to tenant connection and reverted', function () { $tenant = Tenant::create(); $tenant2 = Tenant::create(); expect(getBatchRepositoryConnectionName())->toBe('central'); tenancy()->initialize($tenant); expect(getBatchRepositoryConnectionName())->toBe('tenant'); tenancy()->initialize($tenant2); expect(getBatchRepositoryConnectionName())->toBe('tenant'); tenancy()->end(); expect(getBatchRepositoryConnectionName())->toBe('central'); })->skip(fn() => version_compare(app()->version(), '8.0', '<'), 'Job batches are only supported in Laravel 8+'); function getBatchRepositoryConnectionName() { return app(BatchRepository::class)->getConnection()->getName(); }