mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 01:34:02 +00:00
CacheManager dependency injection test
This commit is contained in:
parent
70ee83b3b7
commit
222686ec1d
3 changed files with 42 additions and 1 deletions
|
|
@ -40,7 +40,7 @@ class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper
|
||||||
{
|
{
|
||||||
$this->config->set('cache.prefix', $prefix);
|
$this->config->set('cache.prefix', $prefix);
|
||||||
|
|
||||||
$this->app['cache']->forgetDriver($this->storeName);
|
// $this->app['cache']->forgetDriver($this->storeName);
|
||||||
|
|
||||||
// The CacheManager will have the $app['config'] array cached with old prefixes on the 'cache' instance
|
// The CacheManager will have the $app['config'] array cached with old prefixes on the 'cache' instance
|
||||||
// This call will forget the 'cache' instance
|
// This call will forget the 'cache' instance
|
||||||
|
|
|
||||||
24
tests/Etc/CacheAction.php
Normal file
24
tests/Etc/CacheAction.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Tests\Etc;
|
||||||
|
|
||||||
|
use Illuminate\Cache\CacheManager;
|
||||||
|
|
||||||
|
class CacheAction
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected CacheManager $cache
|
||||||
|
){
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
if (tenancy()->initialized) {
|
||||||
|
$this->cache->put('key', tenant()->getTenantKey());
|
||||||
|
} else {
|
||||||
|
$this->cache->put('key', 'central-value');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ use Stancl\Tenancy\Events\TenancyEnded;
|
||||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||||
|
use Stancl\Tenancy\Tests\Etc\CacheAction;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
config([
|
config([
|
||||||
|
|
@ -120,3 +121,19 @@ test('cache base prefix is customizable', function () {
|
||||||
->toBe(app('cache.store')->getPrefix());
|
->toBe(app('cache.store')->getPrefix());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('prefix separate cache well enough using CacheManager dependency injection', function () {
|
||||||
|
app()->make(CacheAction::class)->handle();
|
||||||
|
|
||||||
|
expect(cache('key'))->toBe('central-value');
|
||||||
|
|
||||||
|
$tenant = Tenant::create();
|
||||||
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
|
expect(cache('key'))->toBeNull();
|
||||||
|
app()->make(CacheAction::class)->handle();
|
||||||
|
expect(cache('key'))->toBe($tenant->getTenantKey());
|
||||||
|
|
||||||
|
tenancy()->end();
|
||||||
|
|
||||||
|
expect(cache('key'))->toBe('central-value');
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue