From 5f8a3d2ffe76ae51a454749921c6c3c2922a3dd0 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 11 Oct 2024 22:50:38 +0200 Subject: [PATCH] Improve the tests where the removed universal_channel() was still used (#64) --- ...BroadcastChannelPrefixBootstrapperTest.php | 4 --- tests/BroadcastingTest.php | 29 ++++--------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php b/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php index 29a80cbe..4c3ea30a 100644 --- a/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php +++ b/tests/Bootstrappers/BroadcastChannelPrefixBootstrapperTest.php @@ -48,10 +48,6 @@ test('BroadcastChannelPrefixBootstrapper prefixes the channels events are broadc $table->timestamps(); }); - universal_channel('users.{userId}', function ($user, $userId) { - return User::find($userId)->is($user); - }); - $broadcaster = app(BroadcastManager::class)->driver(); $tenant = Tenant::create(); diff --git a/tests/BroadcastingTest.php b/tests/BroadcastingTest.php index bd15df18..ba221307 100644 --- a/tests/BroadcastingTest.php +++ b/tests/BroadcastingTest.php @@ -138,14 +138,16 @@ test('broadcasting channel helpers register channels correctly', function() { $tenantChannelClosure = $getChannels()->first(fn ($closure, $name) => $name === "{tenant}.$channelName"); expect($tenantChannelClosure)->toBe($centralChannelClosure); - // todo: fix tests from below here as the closure is now NOT modified, the $tenant parameter is expected (when additional parameters are used) and kept - // and the universal_channel() helper was removed (get rid of tests related to testing the helper's behavior, but tests which use universal channels should - // be kept -- the two channels should just be registered by hand per docs instead of using the now removed helper) - // The tenant channels are prefixed with '{tenant}.' // They accept the tenant key, but their closures only run in tenant context when tenancy is initialized // The regular channels don't accept the tenant key, but they also respect the current context // The tenant key is used solely for the name prefixing – the closures can still run in the central context + tenant_channel($channelName, $tenantChannelClosure = function ($user, $tenant, $userName) { + return User::firstWhere('name', $userName)?->is($user) ?? false; + }); + + expect($tenantChannelClosure)->not()->toBe($centralChannelClosure); + expect($tenantChannelClosure($centralUser, $tenant->getTenantKey(), $centralUser->name))->toBeTrue(); expect($tenantChannelClosure($centralUser, $tenant->getTenantKey(), $tenantUser->name))->toBeFalse(); @@ -162,25 +164,6 @@ test('broadcasting channel helpers register channels correctly', function() { expect($getChannels())->toBeEmpty(); - // universal_channel helper registers both the unprefixed and the prefixed broadcasting channel correctly - // Using the tenant_channel helper + basic channel registration (Broadcast::channel()) - universal_channel($channelName, $channelClosure); - - // Regular channel registered correctly - $centralChannelClosure = $getChannels()->first(fn ($closure, $name) => $name === $channelName); - expect($centralChannelClosure)->not()->toBeNull(); - - // Tenant channel registered correctly - $tenantChannelClosure = $getChannels()->first(fn ($closure, $name) => $name === "{tenant}.$channelName"); - expect($tenantChannelClosure) - ->not()->toBeNull() // Channel registered - ->not()->toBe($centralChannelClosure); // The tenant channel callback is different – after the auth user, it accepts the tenant ID - - $broadcastManager->purge($driver); - $broadcastManager->extend($driver, fn () => new NullBroadcaster); - - expect($getChannels())->toBeEmpty(); - // Global channel helper prefixes the channel name with 'global__' global_channel($channelName, $channelClosure);