mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-06 03:34:04 +00:00
Convert test cases
This commit is contained in:
parent
405b91085e
commit
a8dcd0dfc9
27 changed files with 3059 additions and 3658 deletions
|
|
@ -2,111 +2,97 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Stancl\Tenancy\Resolvers\DomainTenantResolver;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
|
||||
class CachedTenantResolverTest extends TestCase
|
||||
{
|
||||
public function tearDown(): void
|
||||
{
|
||||
DomainTenantResolver::$shouldCache = false;
|
||||
uses(Stancl\Tenancy\Tests\TestCase::class);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
afterEach(function () {
|
||||
DomainTenantResolver::$shouldCache = false;
|
||||
});
|
||||
|
||||
/** @test */
|
||||
public function tenants_can_be_resolved_using_the_cached_resolver()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
$tenant->domains()->create([
|
||||
'domain' => 'acme',
|
||||
]);
|
||||
test('tenants can be resolved using the cached resolver', function () {
|
||||
$tenant = Tenant::create();
|
||||
$tenant->domains()->create([
|
||||
'domain' => 'acme',
|
||||
]);
|
||||
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
}
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
});
|
||||
|
||||
/** @test */
|
||||
public function the_underlying_resolver_is_not_touched_when_using_the_cached_resolver()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
$tenant->domains()->create([
|
||||
'domain' => 'acme',
|
||||
]);
|
||||
test('the underlying resolver is not touched when using the cached resolver', function () {
|
||||
$tenant = Tenant::create();
|
||||
$tenant->domains()->create([
|
||||
'domain' => 'acme',
|
||||
]);
|
||||
|
||||
DB::enableQueryLog();
|
||||
DB::enableQueryLog();
|
||||
|
||||
DomainTenantResolver::$shouldCache = false;
|
||||
DomainTenantResolver::$shouldCache = false;
|
||||
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertNotEmpty(DB::getQueryLog()); // not empty
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertNotEmpty(DB::getQueryLog()); // not empty
|
||||
|
||||
DomainTenantResolver::$shouldCache = true;
|
||||
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
|
||||
}
|
||||
$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
|
||||
});
|
||||
|
||||
/** @test */
|
||||
public function cache_is_invalidated_when_the_tenant_is_updated()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
$tenant->createDomain([
|
||||
'domain' => 'acme',
|
||||
]);
|
||||
test('cache is invalidated when the tenant is updated', function () {
|
||||
$tenant = Tenant::create();
|
||||
$tenant->createDomain([
|
||||
'domain' => 'acme',
|
||||
]);
|
||||
|
||||
DB::enableQueryLog();
|
||||
DB::enableQueryLog();
|
||||
|
||||
DomainTenantResolver::$shouldCache = true;
|
||||
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
|
||||
$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->update([
|
||||
'foo' => 'bar',
|
||||
]);
|
||||
$tenant->update([
|
||||
'foo' => 'bar',
|
||||
]);
|
||||
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertNotEmpty(DB::getQueryLog()); // not empty
|
||||
}
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertNotEmpty(DB::getQueryLog()); // not empty
|
||||
});
|
||||
|
||||
/** @test */
|
||||
public function cache_is_invalidated_when_a_tenants_domain_is_changed()
|
||||
{
|
||||
$tenant = Tenant::create();
|
||||
$tenant->createDomain([
|
||||
'domain' => 'acme',
|
||||
]);
|
||||
test('cache is invalidated when a tenants domain is changed', function () {
|
||||
$tenant = Tenant::create();
|
||||
$tenant->createDomain([
|
||||
'domain' => 'acme',
|
||||
]);
|
||||
|
||||
DB::enableQueryLog();
|
||||
DB::enableQueryLog();
|
||||
|
||||
DomainTenantResolver::$shouldCache = true;
|
||||
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
|
||||
$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->createDomain([
|
||||
'domain' => 'bar',
|
||||
]);
|
||||
$tenant->createDomain([
|
||||
'domain' => 'bar',
|
||||
]);
|
||||
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertNotEmpty(DB::getQueryLog()); // not empty
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('acme')));
|
||||
$this->assertNotEmpty(DB::getQueryLog()); // not empty
|
||||
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('bar')));
|
||||
$this->assertNotEmpty(DB::getQueryLog()); // not empty
|
||||
}
|
||||
}
|
||||
DB::flushQueryLog();
|
||||
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('bar')));
|
||||
$this->assertNotEmpty(DB::getQueryLog()); // not empty
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue