mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:14:04 +00:00
Features refactor
Features are now *always* bootstrapped, even if Tenancy is not resolved from the container. Previous implementations include https://github.com/tenancy-for-laravel/v4/pull/19 https://github.com/archtechx/tenancy/pull/1021 Bug originally reported here https://github.com/archtechx/tenancy/issues/949 This implementation is much simpler, we do not distinguish between features that should be "always bootstrapped" and features that should only be bootstrapped after Tenancy is resolved. All features should work without issues if they're bootstrapped when TSP::boot() is called. We also add a Tenancy::bootstrapFeatures() method that can be used to bootstrap any features dynamically added at runtime that weren't bootstrapped in TSP::boot(). The function keeps track of which features were already bootstrapped so it doesn't bootstrap them again. The only potentialy risky thing in this implementation is that we're now resolving Tenancy in TSP::boot() (previously Tenancy was not being resolved) but that shouldn't be causing any issues.
This commit is contained in:
parent
33e4a8e4e2
commit
4578c9ed7d
15 changed files with 80 additions and 45 deletions
|
|
@ -63,7 +63,7 @@ test('sqlite ATTACH statements can be blocked', function (bool $disallow) {
|
|||
return json_encode(DB::select(request('q2')));
|
||||
});
|
||||
|
||||
tenancy(); // trigger features: todo@samuel remove after feature refactor
|
||||
tenancy()->bootstrapFeatures();
|
||||
|
||||
if ($disallow) {
|
||||
expect(fn () => pest()->post('/central-sqli', [
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ test('tenant redirect macro replaces only the hostname', function () {
|
|||
'tenancy.features' => [CrossDomainRedirect::class],
|
||||
]);
|
||||
|
||||
tenancy()->bootstrapFeatures();
|
||||
|
||||
Route::get('/foobar', function () {
|
||||
return 'Foo';
|
||||
})->name('home');
|
||||
|
|
|
|||
|
|
@ -11,16 +11,21 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
|||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use function Stancl\Tenancy\Tests\pest;
|
||||
|
||||
beforeEach(function () {
|
||||
config([
|
||||
'tenancy.features' => [TenantConfig::class],
|
||||
'tenancy.bootstrappers' => [],
|
||||
]);
|
||||
|
||||
tenancy()->bootstrapFeatures();
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
TenantConfig::$storageToConfigMap = [];
|
||||
});
|
||||
|
||||
test('nested tenant values are merged', function () {
|
||||
expect(config('whitelabel.theme'))->toBeNull();
|
||||
config([
|
||||
'tenancy.features' => [TenantConfig::class],
|
||||
'tenancy.bootstrappers' => [],
|
||||
]);
|
||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
|
||||
|
|
@ -32,6 +37,9 @@ test('nested tenant values are merged', function () {
|
|||
'whitelabel' => ['config' => ['theme' => 'dark']],
|
||||
]);
|
||||
|
||||
// todo0 one reason why this fails is that tenancy.features was empty
|
||||
// at register() time
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
expect(config('whitelabel.theme'))->toBe('dark');
|
||||
tenancy()->end();
|
||||
|
|
@ -39,10 +47,6 @@ test('nested tenant values are merged', function () {
|
|||
|
||||
test('config is merged and removed', function () {
|
||||
expect(config('services.paypal'))->toBe(null);
|
||||
config([
|
||||
'tenancy.features' => [TenantConfig::class],
|
||||
'tenancy.bootstrappers' => [],
|
||||
]);
|
||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
|
||||
|
|
@ -68,10 +72,6 @@ test('config is merged and removed', function () {
|
|||
|
||||
test('the value can be set to multiple config keys', function () {
|
||||
expect(config('services.paypal'))->toBe(null);
|
||||
config([
|
||||
'tenancy.features' => [TenantConfig::class],
|
||||
'tenancy.bootstrappers' => [],
|
||||
]);
|
||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ beforeEach(function () {
|
|||
|
||||
test('vite bundler ensures vite assets use global_asset when asset_helper_override is enabled', function () {
|
||||
config(['tenancy.features' => [ViteBundler::class]]);
|
||||
tenancy()->bootstrapFeatures();
|
||||
|
||||
withBootstrapping();
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ beforeEach(function () {
|
|||
],
|
||||
]);
|
||||
|
||||
tenancy()->bootstrapFeatures();
|
||||
|
||||
Event::listen(
|
||||
TenantCreated::class,
|
||||
JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue