mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 02:54:03 +00:00
also invalidate the resolver cache when a tenant or related model is deleted
This commit is contained in:
parent
19bc316cf6
commit
1bcc215966
3 changed files with 70 additions and 14 deletions
|
|
@ -109,4 +109,52 @@ class CachedTenantResolverTest extends TestCase
|
|||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('bar')));
|
||||
$this->assertNotEmpty(DB::getQueryLog()); // not empty
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function cache_is_invalidated_when_a_tenants_domain_is_deleted()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
$tenant->createDomain([
|
||||
'domain' => 'acme',
|
||||
]);
|
||||
|
||||
DB::enableQueryLog();
|
||||
|
||||
DomainTenantResolver::$shouldCache = true;
|
||||
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertEmpty(DB::getQueryLog()); // empty
|
||||
|
||||
$tenant->domains()->first()->delete();
|
||||
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertEmpty(DB::getQueryLog()); // not empty
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function cache_is_invalidated_when_a_tenant_is_deleted()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
$tenant->createDomain([
|
||||
'domain' => 'acme',
|
||||
]);
|
||||
|
||||
DB::enableQueryLog();
|
||||
|
||||
DomainTenantResolver::$shouldCache = true;
|
||||
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertEmpty(DB::getQueryLog()); // empty
|
||||
|
||||
$tenant->delete();
|
||||
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertEmpty(DB::getQueryLog()); // not empty
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue