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

Add and test nonTenantCacheDrivers

This commit is contained in:
lukinovec 2023-01-05 12:47:03 +01:00
parent 1c21c66913
commit 4b0df42f8a
2 changed files with 28 additions and 0 deletions

View file

@ -14,6 +14,7 @@ class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper
{
protected string|null $originalPrefix = null;
protected string $storeName;
public static array $nonTenantCacheDrivers = [];
public function __construct(
protected Repository $config,

View file

@ -215,3 +215,30 @@ test('stores other than the default one are not prefixed', function () {
tenancy()->end();
expect(cache()->driver('redis2')->get('key'))->toBe($tenant2->getTenantKey());
});
test('drivers specified in the nonTenantCacheDrivers property do not get prefixed', function() {
PrefixCacheTenancyBootstrapper::$nonTenantCacheDrivers[] = config('cache.default');
$this->app->singleton(CacheService::class);
app()->make(CacheService::class)->handle();
expect(cache('key'))->toBe('central-value');
$tenant1 = Tenant::create();
$tenant2 = Tenant::create();
tenancy()->initialize($tenant1);
expect(cache('key'))->toBe('central-value');
app()->make(CacheService::class)->handle();
expect(cache('key'))->toBe($tenant1->getTenantKey());
tenancy()->initialize($tenant2);
expect(cache('key'))->toBe($tenant1->getTenantKey());
app()->make(CacheService::class)->handle();
expect(cache('key'))->toBe($tenant2->getTenantKey());
tenancy()->end();
expect(cache('key'))->toBe($tenant2->getTenantKey());
});