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

Simplify cache tests

This commit is contained in:
lukinovec 2023-04-13 13:44:00 +02:00
parent 9e15110ad9
commit dd57d9bbdc
2 changed files with 11 additions and 29 deletions

View file

@ -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([

View file

@ -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();