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

Improve the tests for central helper

Signed-off-by: michael lundbøl <michael.lundboel@gmail.com>
This commit is contained in:
michael lundbøl 2020-10-24 16:53:37 +02:00
parent 49e3273aa5
commit b33366e0c0
No known key found for this signature in database
GPG key ID: 213C976E2CFD1CAF

View file

@ -75,9 +75,6 @@ class AutomaticModeTest extends TestCase
/** @test */
public function running_the_central_tenancy_helper_with_tenant_already_initialized()
{
MyBootstrapper::$revertedCallCount = 0;
GlobalRun::$count = 0;
config(['tenancy.bootstrappers' => [
MyBootstrapper::class,
]]);
@ -91,38 +88,44 @@ class AutomaticModeTest extends TestCase
$this->assertSame('acme', app('tenancy_initialized_for_tenant'));
tenancy()->central(function () {
GlobalRun::$count = 1;
$this->assertTrue(app('tenancy_ended'));
$this->assertEmpty(app('tenancy_initialized_for_tenant'));
});
$this->assertSame(1, MyBootstrapper::$revertedCallCount);
$this->assertSame(1, GlobalRun::$count);
$this->assertSame('acme', app('tenancy_initialized_for_tenant'));
}
/** @test */
public function running_the_central_tenancy_helper_with_tenant_not_already_initialized()
{
MyBootstrapper::$revertedCallCount = 0;
GlobalRun::$count = 0;
config(['tenancy.bootstrappers' => [
MyBootstrapper::class,
]]);
tenancy()->central(function () {
GlobalRun::$count = 1;
$runned = 0;
$this->assertFalse(tenancy()->initialized);
$this->assertFalse(app()->bound('tenancy_ended'));
$this->assertFalse(app()->bound('tenancy_initialized_for_tenant'));
tenancy()->central(function () use (&$runned) {
$this->assertFalse(app()->bound('tenancy_initialized_for_tenant'));
$this->assertFalse(app()->bound('tenancy_ended'));
$this->assertFalse(tenancy()->initialized);
$runned = 1;
});
$this->assertSame(0, MyBootstrapper::$revertedCallCount);
$this->assertSame(1, GlobalRun::$count);
$this->assertSame(1, $runned);
$this->assertFalse(app()->bound('tenancy_ended'));
$this->assertFalse(app()->bound('tenancy_initialized_for_tenant'));
$this->assertFalse(tenancy()->initialized);
}
}
class MyBootstrapper implements TenancyBootstrapper
{
public static $revertedCallCount = 0;
public function bootstrap(\Stancl\Tenancy\Contracts\Tenant $tenant)
{
app()->instance('tenancy_initialized_for_tenant', $tenant->getTenantKey());
@ -130,12 +133,7 @@ class MyBootstrapper implements TenancyBootstrapper
public function revert()
{
static::$revertedCallCount++;
app()->instance('tenancy_initialized_for_tenant', '');
app()->instance('tenancy_ended', true);
}
}
class GlobalRun {
public static $count = 0;
}