mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 15:34:03 +00:00
Merge the tenantCacheStores tests
This commit is contained in:
parent
9925e49112
commit
4c9cb7cf51
1 changed files with 31 additions and 15 deletions
|
|
@ -225,7 +225,9 @@ test('specific central cache store can be used inside a service', function () {
|
||||||
expect(cache()->store($cacheStore)->get('key'))->toBe($tenant2->getTenantKey());
|
expect(cache()->store($cacheStore)->get('key'))->toBe($tenant2->getTenantKey());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('stores specified in tenantCacheStores get prefixed', function() {
|
test('only the stores specified in tenantCacheStores get prefixed', function() {
|
||||||
|
config(['cache.stores.redis2' => config('cache.stores.redis')]);
|
||||||
|
|
||||||
// Make the currently used store ('redis') the only store in $tenantCacheStores
|
// Make the currently used store ('redis') the only store in $tenantCacheStores
|
||||||
PrefixCacheTenancyBootstrapper::$tenantCacheStores = ['redis'];
|
PrefixCacheTenancyBootstrapper::$tenantCacheStores = ['redis'];
|
||||||
|
|
||||||
|
|
@ -243,44 +245,58 @@ test('stores specified in tenantCacheStores get prefixed', function() {
|
||||||
$this->app->make(CacheService::class)->handle();
|
$this->app->make(CacheService::class)->handle();
|
||||||
expect(cache('key'))->toBe($tenant1->getTenantKey());
|
expect(cache('key'))->toBe($tenant1->getTenantKey());
|
||||||
|
|
||||||
|
// Switch to an unprefixed store
|
||||||
|
config(['cache.default' => 'redis2']);
|
||||||
|
expect(cache('key'))->toBe($centralValue);
|
||||||
|
config(['cache.default' => 'redis']);
|
||||||
|
|
||||||
tenancy()->initialize($tenant2);
|
tenancy()->initialize($tenant2);
|
||||||
|
|
||||||
expect(cache('key'))->toBeNull();
|
expect(cache('key'))->toBeNull();
|
||||||
$this->app->make(CacheService::class)->handle();
|
$this->app->make(CacheService::class)->handle();
|
||||||
expect(cache('key'))->toBe($tenant2->getTenantKey());
|
expect(cache('key'))->toBe($tenant2->getTenantKey());
|
||||||
|
|
||||||
|
// Switch to an unprefixed store
|
||||||
|
config(['cache.default' => 'redis2']);
|
||||||
|
expect(cache('key'))->toBe($centralValue);
|
||||||
|
// Switch back to the prefixed store
|
||||||
|
config(['cache.default' => 'redis']);
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end();
|
||||||
expect(cache('key'))->toBe($centralValue);
|
expect(cache('key'))->toBe($centralValue);
|
||||||
});
|
|
||||||
|
|
||||||
test('stores not specified in tenantCacheStores do not get prefixed', function() {
|
|
||||||
config(['cache.stores.redis2' => config('cache.stores.redis')]);
|
|
||||||
config(['cache.default' => 'redis2']);
|
|
||||||
// Make 'redis' the only store in $tenantCacheStores so that the current store ('redis2') doesn't get prefixed
|
|
||||||
PrefixCacheTenancyBootstrapper::$tenantCacheStores = ['redis'];
|
|
||||||
|
|
||||||
$this->app->singleton(CacheService::class);
|
|
||||||
|
|
||||||
$this->app->make(CacheService::class)->handle();
|
$this->app->make(CacheService::class)->handle();
|
||||||
expect(cache('key'))->toBe('central-value');
|
expect(cache('key'))->toBe($centralValue);
|
||||||
|
|
||||||
$tenant1 = Tenant::create();
|
$tenant1 = Tenant::create();
|
||||||
$tenant2 = Tenant::create();
|
$tenant2 = Tenant::create();
|
||||||
|
|
||||||
tenancy()->initialize($tenant1);
|
tenancy()->initialize($tenant1);
|
||||||
|
|
||||||
// The cache isn't prefixed, so it isn't separated
|
expect(cache('key'))->toBeNull();
|
||||||
expect(cache('key'))->toBe('central-value');
|
|
||||||
$this->app->make(CacheService::class)->handle();
|
$this->app->make(CacheService::class)->handle();
|
||||||
expect(cache('key'))->toBe($tenant1->getTenantKey());
|
expect(cache('key'))->toBe($tenant1->getTenantKey());
|
||||||
|
|
||||||
|
// Switch to an unprefixed store
|
||||||
|
config(['cache.default' => 'redis2']);
|
||||||
|
expect(cache('key'))->toBe($centralValue);
|
||||||
|
// Switch back to the prefixed store
|
||||||
|
config(['cache.default' => 'redis']);
|
||||||
|
|
||||||
tenancy()->initialize($tenant2);
|
tenancy()->initialize($tenant2);
|
||||||
|
|
||||||
expect(cache('key'))->toBe($tenant1->getTenantKey());
|
expect(cache('key'))->toBeNull();
|
||||||
$this->app->make(CacheService::class)->handle();
|
$this->app->make(CacheService::class)->handle();
|
||||||
expect(cache('key'))->toBe($tenant2->getTenantKey());
|
expect(cache('key'))->toBe($tenant2->getTenantKey());
|
||||||
|
|
||||||
|
// Switch to an unprefixed store
|
||||||
|
config(['cache.default' => 'redis2']);
|
||||||
|
expect(cache('key'))->toBe($centralValue);
|
||||||
|
// Switch back to the prefixed store
|
||||||
|
config(['cache.default' => 'redis']);
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end();
|
||||||
expect(cache('key'))->toBe($tenant2->getTenantKey());
|
expect(cache('key'))->toBe($centralValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('non default stores get prefixed too', function () {
|
test('non default stores get prefixed too', function () {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue