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

Fix event tests

This commit is contained in:
Samuel Štancl 2019-09-16 18:38:23 +02:00
parent a9c37d1535
commit 7e645a3312
3 changed files with 20 additions and 34 deletions

View file

@ -9,13 +9,15 @@ use Tenancy;
class TenantManagerEventsTest extends TestCase
{
public $autoInitTenancy = false;
/** @test */
public function bootstrapping_event_works()
{
$id = Tenant::new()->withDomains(['foo.localhost'])->save()['id'];
Tenancy::eventListener('bootstrapping', function ($tenantManager) use ($id) {
if ($tenantManager->tenant['id'] === $id) {
if ($tenantManager->getTenant('id') === $id) {
config(['tenancy.foo' => 'bar']);
}
});
@ -31,7 +33,7 @@ class TenantManagerEventsTest extends TestCase
$id = Tenant::new()->withDomains(['foo.localhost'])->save()['id'];
Tenancy::eventListener('bootstrapped', function ($tenantManager) use ($id) {
if ($tenantManager->tenant['id'] === $id) {
if ($tenantManager->getTenant('id') === $id) {
config(['tenancy.foo' => 'bar']);
}
});
@ -47,7 +49,7 @@ class TenantManagerEventsTest extends TestCase
$id = Tenant::new()->withDomains(['foo.localhost'])->save()['id'];
Tenancy::eventListener('ending', function ($tenantManager) use ($id) {
if ($tenantManager->tenant['id'] === $id) {
if ($tenantManager->getTenant('id') === $id) {
config(['tenancy.foo' => 'bar']);
}
});
@ -62,12 +64,10 @@ class TenantManagerEventsTest extends TestCase
/** @test */
public function ended_event_works()
{
$id = Tenant::new()->withDomains(['foo.localhost'])->save()['id'];
Tenant::new()->withDomains(['foo.localhost'])->save()['id'];
Tenancy::eventListener('ended', function ($tenantManager) use ($id) {
if ($tenantManager->tenant['id'] === $id) {
config(['tenancy.foo' => 'bar']);
}
Tenancy::eventListener('ended', function ($tenantManager) {
config(['tenancy.foo' => 'bar']);
});
$this->assertSame(null, config('tenancy.foo'));
@ -77,21 +77,6 @@ class TenantManagerEventsTest extends TestCase
$this->assertSame('bar', config('tenancy.foo'));
}
/** @test */
public function event_returns_a_collection()
{
// Note: The event() method should not be called by your code.
tenancy()->bootstrapping(function ($tenancy) {
return ['database'];
});
tenancy()->bootstrapping(function ($tenancy) {
return ['redis', 'cache'];
});
$prevents = tenancy()->event('bootstrapping');
$this->assertEquals(collect(['database', 'redis', 'cache']), $prevents);
}
/** @test */
public function database_can_be_reconnected_using_event_hooks()
{
@ -103,8 +88,8 @@ class TenantManagerEventsTest extends TestCase
$id = Tenant::create('abc.localhost')['id'];
Tenancy::eventListener('bootstrapping', function ($tenancy) use ($id) {
if ($tenancy->tenant['id'] === $id) {
$tenancy->database->useConnection('tenantabc');
if ($tenancy->getTenant()['id'] === $id) {
$tenancy->database->switchConnection('tenantabc');
return ['database'];
}
@ -126,8 +111,8 @@ class TenantManagerEventsTest extends TestCase
$id = Tenant::create('abc.localhost')['id'];
Tenancy::eventListener('bootstrapping', function ($tenancy) use ($id) {
if ($tenancy->tenant['id'] === $id) {
$tenancy->database->useConnection('tenantabc');
if ($tenancy->getTenant()['id'] === $id) {
$tenancy->database->switchConnection('tenantabc');
// return ['database'];
}
});