|
44 | 44 |
|
45 | 45 | afterEach($cleanup); |
46 | 46 |
|
47 | | -test('BroadcastingConfigBootstrapper binds a fresh BroadcastManager and reverts the binding when tenancy is ended', function () { |
48 | | - config(['tenancy.bootstrappers' => [BroadcastingConfigBootstrapper::class]]); |
49 | | - |
50 | | - $centralManager = app(BroadcastManager::class); |
51 | | - |
52 | | - tenancy()->initialize(Tenant::create()); |
53 | | - |
54 | | - expect(app(BroadcastManager::class)) |
55 | | - ->toBeInstanceOf(BroadcastManager::class) |
56 | | - ->not()->toBe($centralManager); |
57 | | - |
58 | | - tenancy()->end(); |
59 | | - |
60 | | - expect(app(BroadcastManager::class))->toBe($centralManager); |
61 | | -}); |
62 | | - |
63 | | -test('bound broadcaster matches the manager default driver in every context and ending tenancy reverts it to the original instance', function () { |
| 47 | +test('each context uses its own manager and broadcaster instances, and the bound broadcaster matches the manager default driver', function () { |
64 | 48 | config([ |
65 | 49 | 'tenancy.bootstrappers' => [BroadcastingConfigBootstrapper::class], |
66 | 50 | 'broadcasting.default' => 'testing', |
|
69 | 53 |
|
70 | 54 | app(BroadcastManager::class)->extend('testing', fn ($app, $config) => new TestingBroadcaster('testing', $config)); |
71 | 55 |
|
| 56 | + $originalManager = app(BroadcastManager::class); |
72 | 57 | $originalBroadcaster = app(BroadcasterContract::class); |
73 | 58 |
|
74 | 59 | // The bound broadcaster and the manager's default driver should be the same instance in every context |
75 | 60 | expect(app(BroadcasterContract::class))->toBe(app(BroadcastManager::class)->driver()); |
76 | 61 |
|
77 | 62 | tenancy()->initialize(Tenant::create()); |
78 | 63 |
|
79 | | - // BroadcastingConfigBootstrapper binds a freshly resolved broadcaster |
| 64 | + // BroadcastingConfigBootstrapper binds a fresh manager and a freshly resolved broadcaster |
| 65 | + expect(app(BroadcastManager::class))->not()->toBe($originalManager); |
80 | 66 | expect(app(BroadcasterContract::class))->not()->toBe($originalBroadcaster); |
81 | 67 |
|
82 | 68 | // The bound broadcaster is the same instance as the tenant BroadcastManager's default driver |
83 | 69 | expect(app(BroadcasterContract::class))->toBe(app(BroadcastManager::class)->driver()); |
84 | 70 |
|
85 | 71 | tenancy()->end(); |
86 | 72 |
|
87 | | - // Ending tenancy reverts the binding back to the original broadcaster instance |
88 | | - expect($originalBroadcaster)->toBe(app(BroadcasterContract::class)); |
| 73 | + // Ending tenancy reverts the bindings back to the original instances |
| 74 | + expect(app(BroadcastManager::class))->toBe($originalManager); |
| 75 | + expect(app(BroadcasterContract::class))->toBe($originalBroadcaster); |
| 76 | + |
89 | 77 | // The bound broadcaster is still the same as the central manager's default driver |
90 | 78 | expect(app(BroadcasterContract::class))->toBe(app(BroadcastManager::class)->driver()); |
91 | 79 | }); |
|
0 commit comments