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:
parent
1c21c66913
commit
4b0df42f8a
2 changed files with 28 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue