From 6a8358fd80469b0365089761fb2aff58cd89e81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 6 Aug 2025 19:54:12 +0200 Subject: [PATCH] Reset adjustCacheManagerUsing in revert() and TestCase --- src/Bootstrappers/DatabaseCacheBootstrapper.php | 6 ++++++ tests/TestCase.php | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/Bootstrappers/DatabaseCacheBootstrapper.php b/src/Bootstrappers/DatabaseCacheBootstrapper.php index 09859eff..27754f9e 100644 --- a/src/Bootstrappers/DatabaseCacheBootstrapper.php +++ b/src/Bootstrappers/DatabaseCacheBootstrapper.php @@ -52,6 +52,8 @@ class DatabaseCacheBootstrapper implements TenancyBootstrapper $this->originalConnections[$storeName] = $this->config->get("cache.stores.{$storeName}.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}.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. TenancyServiceProvider::$adjustCacheManagerUsing = function (CacheManager $manager) use ($stores) { foreach ($stores as $storeName) { + // @phpstan-ignore-next-line method.notFound $manager->store($storeName)->getStore()->setConnection( DB::connection($this->originalConnections[$storeName] ?? config('tenancy.database.central_connection')) ); + // @phpstan-ignore-next-line method.notFound $manager->store($storeName)->getStore()->setLockConnection( DB::connection($this->originalLockConnections[$storeName] ?? config('tenancy.database.central_connection')) ); @@ -83,6 +87,8 @@ class DatabaseCacheBootstrapper implements TenancyBootstrapper $this->cache->purge($storeName); } + + TenancyServiceProvider::$adjustCacheManagerUsing = null; } /** diff --git a/tests/TestCase.php b/tests/TestCase.php index 90dcf22b..6039134e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -39,6 +39,10 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase ini_set('memory_limit', '1G'); + TenancyServiceProvider::$configure = null; + TenancyServiceProvider::$registerForgetTenantParameterListener = true; + TenancyServiceProvider::$adjustCacheManagerUsing = null; + Redis::connection('default')->flushdb(); Redis::connection('cache')->flushdb(); Artisan::call('cache:clear memcached'); // flush memcached