1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 15:14:04 +00:00

Bootstrap features manually in tests

This commit is contained in:
lukinovec 2023-02-23 16:22:52 +01:00
parent 3e6dd646ae
commit 91f8adb698
3 changed files with 23 additions and 17 deletions

View file

@ -2,13 +2,23 @@
declare(strict_types=1); declare(strict_types=1);
use Stancl\Tenancy\Tests\Etc\Tenant;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Events\TenancyEnded; use Stancl\Tenancy\Events\TenancyEnded;
use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Features\TenantConfig; use Stancl\Tenancy\Features\TenantConfig;
use Stancl\Tenancy\TenancyServiceProvider;
use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Tests\Etc\Tenant;
beforeEach(function() {
config([
'tenancy.features' => [TenantConfig::class],
'tenancy.bootstrappers' => [],
]);
TenancyServiceProvider::bootstrapFeatures();
});
afterEach(function () { afterEach(function () {
TenantConfig::$storageToConfigMap = []; TenantConfig::$storageToConfigMap = [];
@ -16,10 +26,7 @@ afterEach(function () {
test('nested tenant values are merged', function () { test('nested tenant values are merged', function () {
expect(config('whitelabel.theme'))->toBeNull(); expect(config('whitelabel.theme'))->toBeNull();
config([
'tenancy.features' => [TenantConfig::class],
'tenancy.bootstrappers' => [],
]);
Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
Event::listen(TenancyEnded::class, RevertToCentralContext::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class);
@ -37,11 +44,8 @@ test('nested tenant values are merged', function () {
}); });
test('config is merged and removed', function () { test('config is merged and removed', function () {
expect(config('services.paypal'))->toBe(null); expect(config('services.paypal'))->toBeNull();
config([
'tenancy.features' => [TenantConfig::class],
'tenancy.bootstrappers' => [],
]);
Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
Event::listen(TenancyEnded::class, RevertToCentralContext::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class);
@ -64,13 +68,9 @@ test('config is merged and removed', function () {
'private' => null, 'private' => null,
], config('services.paypal')); ], config('services.paypal'));
}); });
test('the value can be set to multiple config keys', function () { test('the value can be set to multiple config keys', function () {
expect(config('services.paypal'))->toBe(null); expect(config('services.paypal'))->toBeNull();
config([
'tenancy.features' => [TenantConfig::class],
'tenancy.bootstrappers' => [],
]);
Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
Event::listen(TenancyEnded::class, RevertToCentralContext::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class);

View file

@ -6,6 +6,7 @@ use Illuminate\Foundation\Vite;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
use Stancl\Tenancy\Vite as StanclVite; use Stancl\Tenancy\Vite as StanclVite;
use Stancl\Tenancy\Features\ViteBundler; use Stancl\Tenancy\Features\ViteBundler;
use Stancl\Tenancy\TenancyServiceProvider;
test('vite helper uses our custom class', function() { test('vite helper uses our custom class', function() {
$vite = app(Vite::class); $vite = app(Vite::class);
@ -17,6 +18,8 @@ test('vite helper uses our custom class', function() {
'tenancy.features' => [ViteBundler::class], 'tenancy.features' => [ViteBundler::class],
]); ]);
TenancyServiceProvider::bootstrapFeatures();
$tenant = Tenant::create(); $tenant = Tenant::create();
tenancy()->initialize($tenant); tenancy()->initialize($tenant);

View file

@ -15,6 +15,7 @@ use Illuminate\Support\Facades\Route;
use Stancl\Tenancy\Events\TenancyEnded; use Stancl\Tenancy\Events\TenancyEnded;
use Stancl\Tenancy\Jobs\CreateDatabase; use Stancl\Tenancy\Jobs\CreateDatabase;
use Stancl\Tenancy\Events\TenantCreated; use Stancl\Tenancy\Events\TenantCreated;
use Stancl\Tenancy\TenancyServiceProvider;
use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Features\UserImpersonation; use Stancl\Tenancy\Features\UserImpersonation;
use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\BootstrapTenancy;
@ -41,6 +42,8 @@ beforeEach(function () {
], ],
]); ]);
TenancyServiceProvider::bootstrapFeatures();
Event::listen( Event::listen(
TenantCreated::class, TenantCreated::class,
JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) { JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {