1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 22:04:04 +00:00

Convert test cases

This commit is contained in:
Shift 2022-06-28 20:56:04 +00:00
parent 405b91085e
commit a8dcd0dfc9
No known key found for this signature in database
GPG key ID: 5A96F038425C5A1C
27 changed files with 3059 additions and 3658 deletions

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
namespace Stancl\Tenancy\Tests;
use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper;
use Stancl\Tenancy\Events\TenancyEnded;
@ -13,49 +11,43 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Tests\Etc\Tenant;
class GlobalCacheTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
uses(Stancl\Tenancy\Tests\TestCase::class);
config(['tenancy.bootstrappers' => [
CacheTenancyBootstrapper::class,
]]);
beforeEach(function () {
config(['tenancy.bootstrappers' => [
CacheTenancyBootstrapper::class,
]]);
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
}
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
});
/** @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'));
test('global cache manager stores data in global cache', function () {
$this->assertSame(null, cache('foo'));
GlobalCache::put(['foo' => 'bar'], 1);
$this->assertSame('bar', GlobalCache::get('foo'));
$tenant1 = Tenant::create();
tenancy()->initialize($tenant1);
$this->assertSame('bar', GlobalCache::get('foo'));
$tenant1 = Tenant::create();
tenancy()->initialize($tenant1);
$this->assertSame('bar', GlobalCache::get('foo'));
GlobalCache::put(['abc' => 'xyz'], 1);
cache(['def' => 'ghi'], 10);
$this->assertSame('ghi', cache('def'));
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'));
tenancy()->end();
$this->assertSame('xyz', GlobalCache::get('abc'));
$this->assertSame('bar', GlobalCache::get('foo'));
$this->assertSame(null, cache('def'));
$tenant2 = Tenant::create();
tenancy()->initialize($tenant2);
$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'));
$tenant2 = Tenant::create();
tenancy()->initialize($tenant2);
$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()->initialize($tenant1);
$this->assertSame('ghi', cache('def'));
}
}
tenancy()->initialize($tenant1);
$this->assertSame('ghi', cache('def'));
});