mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 22:04:05 +00:00
BroadcastingConfigBootstrapper: test persistence of custom driver creators
Test that TenancyBroadcastManager inherits the custom driver creators from the central BroadcastManager.
This commit is contained in:
parent
7d749eb592
commit
2ecc94d8e8
1 changed files with 40 additions and 4 deletions
|
|
@ -94,6 +94,45 @@ test('broadcasting config bootstrapper maps the config to broadcaster credential
|
||||||
expect(Broadcast::driver()->config['key'])->toBe('central_key');
|
expect(Broadcast::driver()->config['key'])->toBe('central_key');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('tenant broadcast manager receives the custom driver creators of the central broadcast manager', function() {
|
||||||
|
config([
|
||||||
|
'tenancy.bootstrappers' => [
|
||||||
|
BroadcastingConfigBootstrapper::class,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$tenant = Tenant::create();
|
||||||
|
$tenant2 = Tenant::create();
|
||||||
|
|
||||||
|
app(BroadcastManager::class)->extend('testing', $testingClosure = fn($app, $config) => new TestingBroadcaster('testing', $config));
|
||||||
|
|
||||||
|
$originalCustomCreators = invade(app(BroadcastManager::class))->customCreators;
|
||||||
|
|
||||||
|
expect($originalCustomCreators['testing'])->toBe($testingClosure);
|
||||||
|
|
||||||
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
|
app(BroadcastManager::class)->extend(
|
||||||
|
'testing-tenant1',
|
||||||
|
$testingTenant1Closure = fn($app, $config) => new TestingBroadcaster('testing-tenant1', $config)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Current BroadcastManager instance has the original custom creators plus the newly registered testing-tenant1 creator
|
||||||
|
expect(invade(app(BroadcastManager::class))->customCreators)->toBe($originalCustomCreators + ['testing-tenant1' => $testingTenant1Closure]);
|
||||||
|
|
||||||
|
tenancy()->initialize($tenant2);
|
||||||
|
|
||||||
|
// Current BroadcastManager only has the original custom creators,
|
||||||
|
// the creator added in the previous tenant's context doesn't persist.
|
||||||
|
expect(invade(app(BroadcastManager::class))->customCreators)->toBe($originalCustomCreators);
|
||||||
|
|
||||||
|
tenancy()->end();
|
||||||
|
|
||||||
|
// Ending tenancy reverts the BroadcastManager binding back to the original state,
|
||||||
|
// the creator registered in the tenant context doesn't persist.
|
||||||
|
expect(invade(app(BroadcastManager::class))->customCreators)->toBe($originalCustomCreators);
|
||||||
|
});
|
||||||
|
|
||||||
test('new broadcasters get the channels from the previously bound broadcaster', function() {
|
test('new broadcasters get the channels from the previously bound broadcaster', function() {
|
||||||
config(['tenancy.bootstrappers' => [BroadcastingConfigBootstrapper::class]]);
|
config(['tenancy.bootstrappers' => [BroadcastingConfigBootstrapper::class]]);
|
||||||
config([
|
config([
|
||||||
|
|
@ -103,21 +142,18 @@ test('new broadcasters get the channels from the previously bound broadcaster',
|
||||||
|
|
||||||
TenancyBroadcastManager::$tenantBroadcasters[] = $driver;
|
TenancyBroadcastManager::$tenantBroadcasters[] = $driver;
|
||||||
|
|
||||||
$registerTestingBroadcaster = fn() => app(BroadcastManager::class)->extend('testing', fn($app, $config) => new TestingBroadcaster('testing'));
|
app(BroadcastManager::class)->extend('testing', fn($app, $config) => new TestingBroadcaster('testing'));
|
||||||
$getCurrentChannels = fn() => array_keys(invade(app(BroadcastManager::class)->driver())->channels);
|
$getCurrentChannels = fn() => array_keys(invade(app(BroadcastManager::class)->driver())->channels);
|
||||||
|
|
||||||
$registerTestingBroadcaster();
|
|
||||||
Broadcast::channel($channel = 'testing-channel', fn() => true);
|
Broadcast::channel($channel = 'testing-channel', fn() => true);
|
||||||
|
|
||||||
expect($channel)->toBeIn($getCurrentChannels());
|
expect($channel)->toBeIn($getCurrentChannels());
|
||||||
|
|
||||||
tenancy()->initialize(Tenant::create());
|
tenancy()->initialize(Tenant::create());
|
||||||
$registerTestingBroadcaster();
|
|
||||||
|
|
||||||
expect($channel)->toBeIn($getCurrentChannels());
|
expect($channel)->toBeIn($getCurrentChannels());
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end();
|
||||||
$registerTestingBroadcaster();
|
|
||||||
|
|
||||||
expect($channel)->toBeIn($getCurrentChannels());
|
expect($channel)->toBeIn($getCurrentChannels());
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue