mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 09:34:05 +00:00
Merge branch '1.x' into telescope-tags
This commit is contained in:
commit
f23fd125b1
9 changed files with 112 additions and 6 deletions
|
|
@ -73,4 +73,36 @@ class CacheManagerTest extends TestCase
|
|||
cache(['foo' => 'xyz'], 1);
|
||||
$this->assertSame('xyz', cache('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function cache_is_persisted()
|
||||
{
|
||||
tenant()->create('foo.localhost');
|
||||
tenancy()->init('foo.localhost');
|
||||
|
||||
cache(['foo' => 'bar'], 10);
|
||||
$this->assertSame('bar', cache('foo'));
|
||||
|
||||
tenancy()->end();
|
||||
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame('bar', cache('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function cache_is_persisted_when_reidentification_is_used()
|
||||
{
|
||||
tenant()->create('foo.localhost');
|
||||
tenant()->create('bar.localhost');
|
||||
tenancy()->init('foo.localhost');
|
||||
|
||||
cache(['foo' => 'bar'], 10);
|
||||
$this->assertSame('bar', cache('foo'));
|
||||
|
||||
tenancy()->init('bar.localhost');
|
||||
tenancy()->end();
|
||||
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame('bar', cache('foo'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
43
tests/GlobalCacheTest.php
Normal file
43
tests/GlobalCacheTest.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use GlobalCache;
|
||||
|
||||
class GlobalCacheTest extends TestCase
|
||||
{
|
||||
public $autoCreateTenant = false;
|
||||
public $autoInitTenancy = false;
|
||||
|
||||
/** @test */
|
||||
public function global_cache_manager_stores_data_in_global_cache()
|
||||
{
|
||||
$this->assertSame(null, cache('foo'));
|
||||
GlobalCache::put(['foo' => 'bar'], 1);
|
||||
$this->assertSame('bar', GlobalCache::get('foo'));
|
||||
|
||||
tenant()->create('foo.localhost');
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame('bar', GlobalCache::get('foo'));
|
||||
|
||||
GlobalCache::put(['abc' => 'xyz'], 1);
|
||||
cache(['def' => 'ghi'], 10);
|
||||
$this->assertSame('ghi', cache('def'));
|
||||
|
||||
tenancy()->end();
|
||||
$this->assertSame('xyz', GlobalCache::get('abc'));
|
||||
$this->assertSame('bar', GlobalCache::get('foo'));
|
||||
$this->assertSame(null, cache('def'));
|
||||
|
||||
tenant()->create('bar.localhost');
|
||||
tenancy()->init('bar.localhost');
|
||||
$this->assertSame('xyz', GlobalCache::get('abc'));
|
||||
$this->assertSame('bar', GlobalCache::get('foo'));
|
||||
$this->assertSame(null, cache('def'));
|
||||
cache(['def' => 'xxx'], 1);
|
||||
$this->assertSame('xxx', cache('def'));
|
||||
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame('ghi', cache('def'));
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
parent::setUp();
|
||||
|
||||
Redis::connection('tenancy')->flushdb();
|
||||
Redis::connection('cache')->flushdb();
|
||||
|
||||
if ($this->autoCreateTenant) {
|
||||
$this->createTenant();
|
||||
|
|
@ -77,6 +78,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
's3',
|
||||
],
|
||||
'tenancy.redis.tenancy' => true,
|
||||
'tenancy.redis.prefixed_connections' => ['default'],
|
||||
'tenancy.migrations_directory' => database_path('../migrations'),
|
||||
]);
|
||||
}
|
||||
|
|
@ -98,7 +100,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
protected function getPackageAliases($app)
|
||||
{
|
||||
return [
|
||||
'Tenancy' => \Stancl\Tenancy\TenancyFacade::class
|
||||
'Tenancy' => \Stancl\Tenancy\TenancyFacade::class,
|
||||
'GlobalCache' => \Stancl\Tenancy\GlobalCacheFacade::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue