From 8a5f5438ffe75acca71f8bd6c7b85e53bb10cb73 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 21 Jul 2026 11:56:03 +0200 Subject: [PATCH] Delete $broadcaster property from the config bootstrapper, stop overriding the static properties in the constructor The $broadcaster property essentially had no real purpose, and there's no reason to override the static properties in the constructor. Instead of that, just get the credentials map in setConfig --- .../BroadcastingConfigBootstrapper.php | 14 +++++++------- .../BroadcastingConfigBootstrapperTest.php | 18 ------------------ 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/Bootstrappers/BroadcastingConfigBootstrapper.php b/src/Bootstrappers/BroadcastingConfigBootstrapper.php index ba417ea6..bc4f75b9 100644 --- a/src/Bootstrappers/BroadcastingConfigBootstrapper.php +++ b/src/Bootstrappers/BroadcastingConfigBootstrapper.php @@ -31,8 +31,6 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper */ public static array $credentialsMap = []; - public static string|null $broadcaster = null; - protected array $originalConfig = []; protected BroadcastManager|null $originalBroadcastManager = null; protected BroadcasterContract|null $originalBroadcaster = null; @@ -59,10 +57,7 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper public function __construct( protected Repository $config, protected Application $app - ) { - static::$broadcaster ??= $config->get('broadcasting.default'); - static::$credentialsMap = array_merge(static::$mapPresets[static::$broadcaster] ?? [], static::$credentialsMap); - } + ) {} public function bootstrap(Tenant $tenant): void { @@ -147,7 +142,12 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper protected function setConfig(Tenant $tenant): void { - foreach (static::$credentialsMap as $configKey => $storageKey) { + $credentialsMap = array_merge( + static::$mapPresets[$this->config->get('broadcasting.default')] ?? [], + static::$credentialsMap, + ); + + foreach ($credentialsMap as $configKey => $storageKey) { $override = $tenant->$storageKey; if (array_key_exists($storageKey, $tenant->getAttributes())) { diff --git a/tests/Bootstrappers/BroadcastingConfigBootstrapperTest.php b/tests/Bootstrappers/BroadcastingConfigBootstrapperTest.php index cd45b5bd..ce898307 100644 --- a/tests/Bootstrappers/BroadcastingConfigBootstrapperTest.php +++ b/tests/Bootstrappers/BroadcastingConfigBootstrapperTest.php @@ -13,7 +13,6 @@ use Illuminate\Support\Facades\Broadcast; use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract; afterEach($cleanup = function () { - BroadcastingConfigBootstrapper::$broadcaster = null; BroadcastingConfigBootstrapper::$credentialsMap = []; BroadcastingConfigBootstrapper::$mapPresets = [ 'pusher' => [ @@ -351,20 +350,3 @@ test('initializing tenancy does not fail when the broadcaster does not extend th ->not()->toBe($centralBroadcaster); }); -test('setting the broadcaster property overrides which map preset is used', function () { - config([ - 'tenancy.bootstrappers' => [BroadcastingConfigBootstrapper::class], - 'broadcasting.default' => 'testing', - 'broadcasting.connections.testing.driver' => 'testing', - 'broadcasting.connections.pusher.key' => 'central_key', - ]); - - app(BroadcastManager::class)->extend('testing', fn () => new TestingBroadcaster('testing')); - - // Use the pusher preset even though the default connection isn't pusher - BroadcastingConfigBootstrapper::$broadcaster = 'pusher'; - - tenancy()->initialize(Tenant::create(['pusher_key' => 'tenant_key'])); - - expect(config('broadcasting.connections.pusher.key'))->toBe('tenant_key'); -});