1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 21:34:04 +00:00

Use tenancy.cache.manager config instead of Stancl\Tenancy\CacheManager

This commit is contained in:
lukinovec 2023-04-18 14:39:35 +02:00
parent 4b862e2bd6
commit b5abe6ef0f

View file

@ -9,7 +9,6 @@ use Stancl\Tenancy\Tests\Etc\CacheService;
use Stancl\Tenancy\Events\TenancyInitialized; 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\CacheManager as TenancyCacheManager;
use Stancl\Tenancy\Tests\Etc\SpecificCacheStoreService; use Stancl\Tenancy\Tests\Etc\SpecificCacheStoreService;
use Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper;
@ -25,7 +24,7 @@ beforeEach(function () {
PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver]; PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver];
PrefixCacheTenancyBootstrapper::$prefixGenerator = null; PrefixCacheTenancyBootstrapper::$prefixGenerator = null;
TenancyCacheManager::$addTags = false; config('tenancy.cache.manager')::$addTags = false;
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,23 +36,25 @@ afterEach(function () {
}); });
test('Tenancy overrides CacheManager', function() { test('Tenancy overrides CacheManager', function() {
expect(app('cache')::class)->toBe(TenancyCacheManager::class); $tenancyCacheManager = config('tenancy.cache.manager');
expect(app(CacheManager::class)::class)->toBe(TenancyCacheManager::class);
expect(app('cache')::class)->toBe($tenancyCacheManager);
expect(app(CacheManager::class)::class)->toBe($tenancyCacheManager);
tenancy()->initialize(Tenant::create(['id' => 'first'])); tenancy()->initialize(Tenant::create(['id' => 'first']));
expect(app('cache')::class)->toBe(TenancyCacheManager::class); expect(app('cache')::class)->toBe($tenancyCacheManager);
expect(app(CacheManager::class)::class)->toBe(TenancyCacheManager::class); expect(app(CacheManager::class)::class)->toBe($tenancyCacheManager);
tenancy()->initialize(Tenant::create(['id' => 'second'])); tenancy()->initialize(Tenant::create(['id' => 'second']));
expect(app('cache')::class)->toBe(TenancyCacheManager::class); expect(app('cache')::class)->toBe($tenancyCacheManager);
expect(app(CacheManager::class)::class)->toBe(TenancyCacheManager::class); expect(app(CacheManager::class)::class)->toBe($tenancyCacheManager);
tenancy()->end(); tenancy()->end();
expect(app('cache')::class)->toBe(TenancyCacheManager::class); expect(app('cache')::class)->toBe($tenancyCacheManager);
expect(app(CacheManager::class)::class)->toBe(TenancyCacheManager::class); expect(app(CacheManager::class)::class)->toBe($tenancyCacheManager);
}); });
test('correct cache prefix is used in all contexts', function () { test('correct cache prefix is used in all contexts', function () {