From dd57d9bbdc7faa63624b796d3973506a499287e2 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Thu, 13 Apr 2023 13:44:00 +0200 Subject: [PATCH] Simplify cache tests --- tests/BootstrapperTest.php | 8 +++++--- tests/GlobalCacheTest.php | 32 ++++++-------------------------- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/tests/BootstrapperTest.php b/tests/BootstrapperTest.php index 9e5f8c72..72ad55de 100644 --- a/tests/BootstrapperTest.php +++ b/tests/BootstrapperTest.php @@ -41,6 +41,7 @@ use Stancl\Tenancy\CacheManager; beforeEach(function () { $this->mockConsoleOutput = false; + CacheManager::$addTags = false; Event::listen( TenantCreated::class, @@ -53,6 +54,10 @@ beforeEach(function () { Event::listen(TenancyEnded::class, RevertToCentralContext::class); }); +afterEach(function () { + CacheManager::$addTags = false; +}); + test('database data is separated', function () { config(['tenancy.bootstrappers' => [ DatabaseTenancyBootstrapper::class, @@ -88,10 +93,7 @@ test('cache data is separated', function (string $bootstrapper) { $cacheDriver = 'redis'; if ($bootstrapper === PrefixCacheTenancyBootstrapper::class) { - CacheManager::$addTags = false; PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver]; - } else { - CacheManager::$addTags = true; } config([ diff --git a/tests/GlobalCacheTest.php b/tests/GlobalCacheTest.php index 44e14dfe..f57cc4f3 100644 --- a/tests/GlobalCacheTest.php +++ b/tests/GlobalCacheTest.php @@ -14,24 +14,16 @@ use Stancl\Tenancy\Bootstrappers\CacheTagsBootstrapper; use Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper; beforeEach(function () { + CacheManager::$addTags = false; + config(['cache.default' => $cacheDriver = 'redis']); + PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver]; + Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class); }); test('global cache manager stores data in global cache', function (string $bootstrapper) { - $cacheDriver = 'redis'; - - if ($bootstrapper === PrefixCacheTenancyBootstrapper::class) { - CacheManager::$addTags = false; - PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver]; - } else { - CacheManager::$addTags = true; - } - - config([ - 'tenancy.bootstrappers' => [$bootstrapper], - 'cache.default' => $cacheDriver, - ]); + config(['tenancy.bootstrappers' => [$bootstrapper]]); expect(cache('foo'))->toBe(null); GlobalCache::put(['foo' => 'bar'], 1); @@ -66,19 +58,7 @@ test('global cache manager stores data in global cache', function (string $boots ]); test('the global_cache helper supports the same syntax as the cache helper', function (string $bootstrapper) { - $cacheDriver = 'redis'; - - if ($bootstrapper === PrefixCacheTenancyBootstrapper::class) { - CacheManager::$addTags = false; - PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver]; - } else { - CacheManager::$addTags = true; - } - - config([ - 'tenancy.bootstrappers' => [$bootstrapper], - 'cache.default' => $cacheDriver, - ]); + config(['tenancy.bootstrappers' => [$bootstrapper]]); $tenant = Tenant::create(); $tenant->enter();