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

Inline variable & config key assignment

This commit is contained in:
lukinovec 2023-04-18 16:10:47 +02:00
parent cb07a47f18
commit 4d387188c5

View file

@ -152,14 +152,13 @@ test('central cache is persisted', function () {
}); });
test('cache base prefix is customizable', function () { test('cache base prefix is customizable', function () {
$originalPrefix = config('cache.prefix');
$prefixBase = 'custom_';
config([ config([
'tenancy.cache.prefix_base' => $prefixBase 'tenancy.cache.prefix_base' => $prefixBase = 'custom_'
]); ]);
$originalPrefix = config('cache.prefix');
$tenant1 = Tenant::create(); $tenant1 = Tenant::create();
tenancy()->initialize($tenant1); tenancy()->initialize($tenant1);
expect($originalPrefix . $prefixBase . $tenant1->getTenantKey() . ':') expect($originalPrefix . $prefixBase . $tenant1->getTenantKey() . ':')
@ -339,12 +338,13 @@ test('cache store prefix generation can be customized', function() {
// Expect the 'redis' store to use the prefix generated by the custom generator // Expect the 'redis' store to use the prefix generated by the custom generator
expect($customPrefixGenerator($tenant) . ':') expect($customPrefixGenerator($tenant) . ':')
->toBe(cache()->getPrefix()) ->toBe(cache()->getPrefix())
->toBe(cache()->store('redis2')->getPrefix()) // Non-default cache stores are prefixed too (when they're in $tenantCacheStores) ->toBe(cache()->store('redis2')->getPrefix()) // Non-default cache stores specified in $tenantCacheStores are prefixed too
->toBe(app('cache')->getPrefix()) ->toBe(app('cache')->getPrefix())
->toBe(app('cache.store')->getPrefix()); ->toBe(app('cache.store')->getPrefix());
config(['cache.default' => 'redis2']); config(['cache.default' => 'redis2']);
// Use different prefix generator
PrefixCacheTenancyBootstrapper::generatePrefixUsing($customPrefixGenerator = function (Tenant $tenant) { PrefixCacheTenancyBootstrapper::generatePrefixUsing($customPrefixGenerator = function (Tenant $tenant) {
return 'redis2_tenant_cache_' . $tenant->getTenantKey(); return 'redis2_tenant_cache_' . $tenant->getTenantKey();
}); });