mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 08:44:04 +00:00
Merge 3de597ad20 into 37b2a91aa9
This commit is contained in:
commit
bbfa9ca7f4
2 changed files with 24 additions and 3 deletions
|
|
@ -18,7 +18,7 @@ class TenancyBroadcastManager extends BroadcastManager
|
||||||
* The reason for recreating the broadcasters is
|
* The reason for recreating the broadcasters is
|
||||||
* to make your app use the correct broadcaster credentials when tenancy is initialized.
|
* to make your app use the correct broadcaster credentials when tenancy is initialized.
|
||||||
*/
|
*/
|
||||||
public static array $tenantBroadcasters = ['pusher', 'ably'];
|
public static array $tenantBroadcasters = ['pusher', 'ably', 'reverb'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the get method so that the broadcasters in $tenantBroadcasters
|
* Override the get method so that the broadcasters in $tenantBroadcasters
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,14 @@ use function Stancl\Tenancy\Tests\withTenantDatabases;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
withTenantDatabases();
|
withTenantDatabases();
|
||||||
TenancyBroadcastManager::$tenantBroadcasters = ['pusher', 'ably'];
|
TenancyBroadcastManager::$tenantBroadcasters = ['pusher', 'ably', 'reverb'];
|
||||||
|
|
||||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
TenancyBroadcastManager::$tenantBroadcasters = ['pusher', 'ably'];
|
TenancyBroadcastManager::$tenantBroadcasters = ['pusher', 'ably', 'reverb'];
|
||||||
});
|
});
|
||||||
|
|
||||||
test('bound broadcaster instance is the same before initializing tenancy and after ending it', function() {
|
test('bound broadcaster instance is the same before initializing tenancy and after ending it', function() {
|
||||||
|
|
@ -172,3 +172,24 @@ test('broadcasting channel helpers register channels correctly', function() {
|
||||||
$foundChannelClosure = $getChannels()->first(fn ($closure, $name) => $name === 'global__' . $channelName);
|
$foundChannelClosure = $getChannels()->first(fn ($closure, $name) => $name === 'global__' . $channelName);
|
||||||
expect($foundChannelClosure)->not()->toBeNull();
|
expect($foundChannelClosure)->not()->toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('reverb driver triggers tenant context binding', function() {
|
||||||
|
$manager = new \Stancl\Tenancy\Overrides\TenancyBroadcastManager(app());
|
||||||
|
|
||||||
|
$manager->extend('reverb', function() {
|
||||||
|
return new \Stancl\Tenancy\Tests\Etc\TestingBroadcaster('tenant_instance');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Bind a "central" broadcaster to the container
|
||||||
|
$centralBroadcaster = new \Stancl\Tenancy\Tests\Etc\TestingBroadcaster('central_instance');
|
||||||
|
app()->instance(\Illuminate\Contracts\Broadcasting\Broadcaster::class, $centralBroadcaster);
|
||||||
|
|
||||||
|
// Resolve the reverb driver
|
||||||
|
$manager->driver('reverb');
|
||||||
|
|
||||||
|
$currentBroadcaster = app(\Illuminate\Contracts\Broadcasting\Broadcaster::class);
|
||||||
|
|
||||||
|
// Assert the broadcaster instance was swapped
|
||||||
|
expect($currentBroadcaster)->not->toBe($centralBroadcaster);
|
||||||
|
expect($currentBroadcaster->message)->toBe('tenant_instance');
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue