mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 15:54:03 +00:00
Add test
This commit is contained in:
parent
8a54e19644
commit
a59d5a1069
2 changed files with 68 additions and 0 deletions
|
|
@ -2,12 +2,14 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Cache\RedisStore;
|
||||
use Illuminate\Cache\CacheManager;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Stancl\Tenancy\Events\TenancyEnded;
|
||||
use Stancl\Tenancy\Tests\Etc\CacheService;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||
use Stancl\Tenancy\Tests\Etc\CacheManagerService;
|
||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||
use Stancl\Tenancy\CacheManager as TenancyCacheManager;
|
||||
use Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper;
|
||||
|
|
@ -174,3 +176,42 @@ test('prefix separate cache well enough using CacheManager dependency injection'
|
|||
|
||||
expect(cache('key'))->toBe('central-value');
|
||||
});
|
||||
|
||||
test('stores other than the default one are not prefixed', function () {
|
||||
config(['cache.default' => 'redis']);
|
||||
config(['cache.stores.redis2' => config('cache.stores.redis')]);
|
||||
|
||||
app(CacheManager::class)->extend('redis2', function($config) {
|
||||
$redis = $this->app['redis'];
|
||||
|
||||
$connection = $config['connection'] ?? 'default';
|
||||
|
||||
$store = new RedisStore($redis, $this->getPrefix($config), $connection);
|
||||
|
||||
return $this->repository(
|
||||
$store->setLockConnection($config['lock_connection'] ?? $connection)
|
||||
);
|
||||
});
|
||||
|
||||
$this->app->singleton(CacheManagerService::class);
|
||||
|
||||
app()->make(CacheManagerService::class)->handle();
|
||||
expect(cache()->driver('redis2')->get('key'))->toBe('central-value');
|
||||
|
||||
$tenant1 = Tenant::create();
|
||||
$tenant2 = Tenant::create();
|
||||
tenancy()->initialize($tenant1);
|
||||
|
||||
expect(cache()->driver('redis2')->get('key'))->toBe('central-value');
|
||||
app()->make(CacheManagerService::class)->handle();
|
||||
expect(cache()->driver('redis2')->get('key'))->toBe($tenant1->getTenantKey());
|
||||
|
||||
tenancy()->initialize($tenant2);
|
||||
|
||||
expect(cache()->driver('redis2')->get('key'))->toBe($tenant1->getTenantKey());
|
||||
app()->make(CacheManagerService::class)->handle();
|
||||
expect(cache()->driver('redis2')->get('key'))->toBe($tenant2->getTenantKey());
|
||||
|
||||
tenancy()->end();
|
||||
expect(cache()->driver('redis2')->get('key'))->toBe($tenant2->getTenantKey());
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue