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

Reset adjustCacheManagerUsing in revert() and TestCase

This commit is contained in:
Samuel Štancl 2025-08-06 19:54:12 +02:00
parent b7df2ca436
commit 6a8358fd80
2 changed files with 10 additions and 0 deletions

View file

@ -52,6 +52,8 @@ class DatabaseCacheBootstrapper implements TenancyBootstrapper
$this->originalConnections[$storeName] = $this->config->get("cache.stores.{$storeName}.connection"); $this->originalConnections[$storeName] = $this->config->get("cache.stores.{$storeName}.connection");
$this->originalLockConnections[$storeName] = $this->config->get("cache.stores.{$storeName}.lock_connection"); $this->originalLockConnections[$storeName] = $this->config->get("cache.stores.{$storeName}.lock_connection");
// todo0 does this handle *already resolved* stores?
$this->config->set("cache.stores.{$storeName}.connection", 'tenant'); $this->config->set("cache.stores.{$storeName}.connection", 'tenant');
$this->config->set("cache.stores.{$storeName}.lock_connection", 'tenant'); $this->config->set("cache.stores.{$storeName}.lock_connection", 'tenant');
@ -64,10 +66,12 @@ class DatabaseCacheBootstrapper implements TenancyBootstrapper
// (this is our only use of $adjustCacheManagerUsing anyway) but ideally at some point we'd have a better solution. // (this is our only use of $adjustCacheManagerUsing anyway) but ideally at some point we'd have a better solution.
TenancyServiceProvider::$adjustCacheManagerUsing = function (CacheManager $manager) use ($stores) { TenancyServiceProvider::$adjustCacheManagerUsing = function (CacheManager $manager) use ($stores) {
foreach ($stores as $storeName) { foreach ($stores as $storeName) {
// @phpstan-ignore-next-line method.notFound
$manager->store($storeName)->getStore()->setConnection( $manager->store($storeName)->getStore()->setConnection(
DB::connection($this->originalConnections[$storeName] ?? config('tenancy.database.central_connection')) DB::connection($this->originalConnections[$storeName] ?? config('tenancy.database.central_connection'))
); );
// @phpstan-ignore-next-line method.notFound
$manager->store($storeName)->getStore()->setLockConnection( $manager->store($storeName)->getStore()->setLockConnection(
DB::connection($this->originalLockConnections[$storeName] ?? config('tenancy.database.central_connection')) DB::connection($this->originalLockConnections[$storeName] ?? config('tenancy.database.central_connection'))
); );
@ -83,6 +87,8 @@ class DatabaseCacheBootstrapper implements TenancyBootstrapper
$this->cache->purge($storeName); $this->cache->purge($storeName);
} }
TenancyServiceProvider::$adjustCacheManagerUsing = null;
} }
/** /**

View file

@ -39,6 +39,10 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
ini_set('memory_limit', '1G'); ini_set('memory_limit', '1G');
TenancyServiceProvider::$configure = null;
TenancyServiceProvider::$registerForgetTenantParameterListener = true;
TenancyServiceProvider::$adjustCacheManagerUsing = null;
Redis::connection('default')->flushdb(); Redis::connection('default')->flushdb();
Redis::connection('cache')->flushdb(); Redis::connection('cache')->flushdb();
Artisan::call('cache:clear memcached'); // flush memcached Artisan::call('cache:clear memcached'); // flush memcached