From b8fddf8a57cae3177673cd0e997393cc375e2232 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Sat, 11 Jul 2026 14:32:03 +0200 Subject: [PATCH] Retrieve the re-registered channel closure to assert what tenant_channel() actually stored https://github.com/archtechx/tenancy/pull/1448#discussion_r3561157859 --- .../BroadcastChannelPrefixBootstrapperTest.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php b/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php index 352a3606..c6554702 100644 --- a/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php +++ b/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php @@ -208,10 +208,16 @@ test('broadcasting channel helpers register channels correctly', function() { return User::firstWhere('name', $userName)?->is($user) ?? false; }); - expect($tenantChannelClosure)->not()->toBe($centralChannelClosure); + // Retrieve the stored closure to verify that re-registering the channel replaced it + // (asserting on $tenantChannelClosure wouldn't tell us what tenant_channel() actually stored) + $reregisteredTenantChannelClosure = $getChannels()->first(fn ($closure, $name) => $name === "{tenant}.$channelName"); - expect($tenantChannelClosure($centralUser, $tenant->getTenantKey(), $centralUser->name))->toBeTrue(); - expect($tenantChannelClosure($centralUser, $tenant->getTenantKey(), $tenantUser->name))->toBeFalse(); + expect($reregisteredTenantChannelClosure) + ->toBe($tenantChannelClosure) + ->not()->toBe($centralChannelClosure); + + expect($reregisteredTenantChannelClosure($centralUser, $tenant->getTenantKey(), $centralUser->name))->toBeTrue(); + expect($reregisteredTenantChannelClosure($centralUser, $tenant->getTenantKey(), $tenantUser->name))->toBeFalse(); tenancy()->initialize($tenant);