mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 15: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:
parent
49e3273aa5
commit
b33366e0c0
1 changed files with 19 additions and 21 deletions
|
|
@ -75,9 +75,6 @@ class AutomaticModeTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function running_the_central_tenancy_helper_with_tenant_already_initialized()
|
public function running_the_central_tenancy_helper_with_tenant_already_initialized()
|
||||||
{
|
{
|
||||||
MyBootstrapper::$revertedCallCount = 0;
|
|
||||||
GlobalRun::$count = 0;
|
|
||||||
|
|
||||||
config(['tenancy.bootstrappers' => [
|
config(['tenancy.bootstrappers' => [
|
||||||
MyBootstrapper::class,
|
MyBootstrapper::class,
|
||||||
]]);
|
]]);
|
||||||
|
|
@ -91,38 +88,44 @@ class AutomaticModeTest extends TestCase
|
||||||
$this->assertSame('acme', app('tenancy_initialized_for_tenant'));
|
$this->assertSame('acme', app('tenancy_initialized_for_tenant'));
|
||||||
|
|
||||||
tenancy()->central(function () {
|
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'));
|
$this->assertSame('acme', app('tenancy_initialized_for_tenant'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function running_the_central_tenancy_helper_with_tenant_not_already_initialized()
|
public function running_the_central_tenancy_helper_with_tenant_not_already_initialized()
|
||||||
{
|
{
|
||||||
MyBootstrapper::$revertedCallCount = 0;
|
|
||||||
GlobalRun::$count = 0;
|
|
||||||
|
|
||||||
config(['tenancy.bootstrappers' => [
|
config(['tenancy.bootstrappers' => [
|
||||||
MyBootstrapper::class,
|
MyBootstrapper::class,
|
||||||
]]);
|
]]);
|
||||||
|
|
||||||
tenancy()->central(function () {
|
$runned = 0;
|
||||||
GlobalRun::$count = 1;
|
|
||||||
|
$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, $runned);
|
||||||
$this->assertSame(1, GlobalRun::$count);
|
|
||||||
|
$this->assertFalse(app()->bound('tenancy_ended'));
|
||||||
$this->assertFalse(app()->bound('tenancy_initialized_for_tenant'));
|
$this->assertFalse(app()->bound('tenancy_initialized_for_tenant'));
|
||||||
|
$this->assertFalse(tenancy()->initialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyBootstrapper implements TenancyBootstrapper
|
class MyBootstrapper implements TenancyBootstrapper
|
||||||
{
|
{
|
||||||
public static $revertedCallCount = 0;
|
|
||||||
|
|
||||||
public function bootstrap(\Stancl\Tenancy\Contracts\Tenant $tenant)
|
public function bootstrap(\Stancl\Tenancy\Contracts\Tenant $tenant)
|
||||||
{
|
{
|
||||||
app()->instance('tenancy_initialized_for_tenant', $tenant->getTenantKey());
|
app()->instance('tenancy_initialized_for_tenant', $tenant->getTenantKey());
|
||||||
|
|
@ -130,12 +133,7 @@ class MyBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
public function revert()
|
public function revert()
|
||||||
{
|
{
|
||||||
static::$revertedCallCount++;
|
app()->instance('tenancy_initialized_for_tenant', '');
|
||||||
app()->instance('tenancy_ended', true);
|
app()->instance('tenancy_ended', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GlobalRun {
|
|
||||||
|
|
||||||
public static $count = 0;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue