From 0c1912b9c58d8e911e5f3a6a0705e9e5342c9154 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 14 Apr 2023 12:33:08 +0200 Subject: [PATCH] Small testing improvements --- tests/BootstrapperTest.php | 23 ++++++++++------------- tests/GlobalCacheTest.php | 8 ++++---- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/tests/BootstrapperTest.php b/tests/BootstrapperTest.php index 36614c34..901587f6 100644 --- a/tests/BootstrapperTest.php +++ b/tests/BootstrapperTest.php @@ -42,6 +42,7 @@ use Stancl\Tenancy\CacheManager; beforeEach(function () { $this->mockConsoleOutput = false; CacheManager::$addTags = false; + PrefixCacheTenancyBootstrapper::$tenantCacheStores = ['redis']; Event::listen( TenantCreated::class, @@ -54,6 +55,11 @@ beforeEach(function () { Event::listen(TenancyEnded::class, RevertToCentralContext::class); }); +afterEach(function () { + CacheManager::$addTags = false; + PrefixCacheTenancyBootstrapper::$tenantCacheStores = []; +}); + test('database data is separated', function () { config(['tenancy.bootstrappers' => [ DatabaseTenancyBootstrapper::class, @@ -86,15 +92,9 @@ test('database data is separated', function () { }); test('cache data is separated', function (string $bootstrapper) { - $cacheDriver = 'redis'; - - if ($bootstrapper === PrefixCacheTenancyBootstrapper::class) { - PrefixCacheTenancyBootstrapper::$tenantCacheStores = [$cacheDriver]; - } - config([ 'tenancy.bootstrappers' => [$bootstrapper], - 'cache.default' => $cacheDriver, + 'cache.default' => 'redis', ]); $tenant1 = Tenant::create(); @@ -128,13 +128,10 @@ test('cache data is separated', function (string $bootstrapper) { // Asset central is still the same expect(Cache::get('foo'))->toBe('central'); - - // Reset the static property - CacheManager::$addTags = false; })->with([ - 'tagging' => CacheTagsBootstrapper::class, - 'prefixing' => PrefixCacheTenancyBootstrapper::class, -])->group('bootstrapper'); + CacheTagsBootstrapper::class, + PrefixCacheTenancyBootstrapper::class, +]); test('redis data is separated', function () { config(['tenancy.bootstrappers' => [ diff --git a/tests/GlobalCacheTest.php b/tests/GlobalCacheTest.php index f57cc4f3..e7b02628 100644 --- a/tests/GlobalCacheTest.php +++ b/tests/GlobalCacheTest.php @@ -53,8 +53,8 @@ test('global cache manager stores data in global cache', function (string $boots tenancy()->initialize($tenant1); expect(cache('def'))->toBe('ghi'); })->with([ - 'tagging' => CacheTagsBootstrapper::class, - 'prefixing' => PrefixCacheTenancyBootstrapper::class, + CacheTagsBootstrapper::class, + PrefixCacheTenancyBootstrapper::class, ]); test('the global_cache helper supports the same syntax as the cache helper', function (string $bootstrapper) { @@ -73,6 +73,6 @@ test('the global_cache helper supports the same syntax as the cache helper', fun expect(cache('foo'))->toBe(null); // tenant cache is not affected })->with([ - 'tagging' => CacheTagsBootstrapper::class, - 'prefixing' => PrefixCacheTenancyBootstrapper::class, + CacheTagsBootstrapper::class, + PrefixCacheTenancyBootstrapper::class, ]);