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

Add a hook that should run before trying to fetch tenants

Signed-off-by: michael lundbøl <michael.lundboel@gmail.com>
This commit is contained in:
michael lundbøl 2020-05-06 21:59:16 +02:00
parent 726a0462eb
commit 39c1e65172
No known key found for this signature in database
GPG key ID: 213C976E2CFD1CAF
4 changed files with 103 additions and 0 deletions

View file

@ -32,4 +32,44 @@ class TenantAwareCommandTest extends TestCase
$this->assertNotEmpty(\DB::table('users')->get());
tenancy()->end();
}
/** @test */
public function commands_can_optionally_specify_a_hook_that_should_be_ran_before_running_the_command_within_a_tenant()
{
$tenant1 = Tenant::new()->save();
$tenant2 = Tenant::new()->save();
\Artisan::call('tenants:migrate', [
'--tenants' => [$tenant1['id'], $tenant2['id']],
]);
$this->withoutMockingConsoleOutput();
$response = $this->artisan('user:add_conditionally', [
'--tenants' => [$tenant1['id'], $tenant2['id']],
'--stop' => true
]);
$this->assertEquals(1, $response);
tenancy()->initializeTenancy($tenant1);
$this->assertEmpty(\DB::table('users')->get());
tenancy()->end();
tenancy()->initializeTenancy($tenant2);
$this->assertEmpty(\DB::table('users')->get());
tenancy()->end();
$this->artisan('user:add_conditionally', [
'--tenants' => [$tenant1['id'], $tenant2['id']],
'--stop' => false
]);
tenancy()->initializeTenancy($tenant1);
$this->assertNotEmpty(\DB::table('users')->get());
tenancy()->end();
tenancy()->initializeTenancy($tenant2);
$this->assertNotEmpty(\DB::table('users')->get());
tenancy()->end();
}
}