1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 12:44:02 +00:00

Add tenancy()->central() helper (#526)

* Add tenancy()->central() helper

* Apply fixes from StyleCI

* Add docblock

* Fix return typehint

Co-authored-by: stancl <stancl@users.noreply.github.com>
This commit is contained in:
Samuel Štancl 2020-11-13 08:15:24 +01:00 committed by GitHub
parent dd1b7fc86d
commit 8f34a733d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 0 deletions

View file

@ -71,6 +71,54 @@ class AutomaticModeTest extends TestCase
$this->assertSame('foobar', app('tenancy_initialized_for_tenant'));
}
/** @test */
public function central_helper_runs_callbacks_in_the_central_state()
{
tenancy()->initialize($tenant = Tenant::create());
tenancy()->central(function () {
$this->assertSame(null, tenant());
});
$this->assertSame($tenant, tenant());
}
/** @test */
public function central_helper_returns_the_value_from_the_callback()
{
tenancy()->initialize(Tenant::create());
$this->assertSame('foo', tenancy()->central(function () {
return 'foo';
}));
}
/** @test */
public function central_helper_reverts_back_to_tenant_context()
{
tenancy()->initialize($tenant = Tenant::create());
tenancy()->central(function () {
//
});
$this->assertSame($tenant, tenant());
}
/** @test */
public function central_helper_doesnt_change_tenancy_state_when_called_in_central_context()
{
$this->assertFalse(tenancy()->initialized);
$this->assertNull(tenant());
tenancy()->central(function () {
//
});
$this->assertFalse(tenancy()->initialized);
$this->assertNull(tenant());
}
}
class MyBootstrapper implements TenancyBootstrapper