mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 13:54:03 +00:00
Add more TenantManager tests
This commit is contained in:
parent
2c69c37032
commit
8d382024a3
3 changed files with 64 additions and 13 deletions
|
|
@ -163,12 +163,6 @@ class TenantManager
|
|||
return config('tenancy.database.prefix') . $tenant['uuid'] . config('tenancy.database.suffix');
|
||||
}
|
||||
|
||||
public function getStoragePath($tenant = []): ?string
|
||||
{
|
||||
$tenant = $tenant ?: $this->tenant;
|
||||
return config('tenancy.filesystem.suffix_base') . $tenant['uuid'];
|
||||
}
|
||||
|
||||
public function setTenant(array $tenant): array
|
||||
{
|
||||
$this->tenant = $tenant;
|
||||
|
|
@ -188,18 +182,19 @@ class TenantManager
|
|||
return collect($this->storage->getAllTenants($uuids));
|
||||
}
|
||||
|
||||
public function actAsId(string $uuid): array
|
||||
/**
|
||||
* Initialize tenancy based on tenant uuid.
|
||||
*
|
||||
* @param string $uuid
|
||||
* @return array
|
||||
*/
|
||||
public function initById(string $uuid): array
|
||||
{
|
||||
$this->setTenant($this->storage->getTenantById($uuid));
|
||||
$this->bootstrap();
|
||||
return $this->tenant;
|
||||
}
|
||||
|
||||
public function actAsDomain(string $domain): string
|
||||
{
|
||||
return $this->init($domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value from the storage for a tenant.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,5 +17,53 @@ class TenantManagerTest extends TestCase
|
|||
$this->assertSame($tenant, tenancy()->tenant);
|
||||
}
|
||||
|
||||
// todo write more tests
|
||||
/** @test */
|
||||
public function invoke_works()
|
||||
{
|
||||
$this->assertSame(tenant('uuid'), tenant()('uuid'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function initById_works()
|
||||
{
|
||||
$tenant = tenant()->create('foo.localhost');
|
||||
|
||||
$this->assertNotSame($tenant, tenancy()->tenant);
|
||||
|
||||
tenancy()->initById($tenant['uuid']);
|
||||
|
||||
$this->assertSame($tenant, tenancy()->tenant);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function findByDomain_works()
|
||||
{
|
||||
$tenant = tenant()->create('foo.localhost');
|
||||
|
||||
$this->assertSame($tenant, tenant()->findByDomain('foo.localhost'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function getIdByDomain_works()
|
||||
{
|
||||
$tenant = tenant()->create('foo.localhost');
|
||||
$this->assertSame(tenant()->getTenantIdByDomain('foo.localhost'), tenant()->getIdByDomain('foo.localhost'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function findWorks()
|
||||
{
|
||||
tenant()->create('dev.localhost');
|
||||
tenancy()->init('dev.localhost');
|
||||
|
||||
$this->assertSame(tenant()->tenant, tenant()->find(tenant('uuid')));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function getTenantByIdWorks()
|
||||
{
|
||||
$tenant = tenant()->create('foo.localhost');
|
||||
|
||||
$this->assertSame($tenant, tenancy()->getTenantById($tenant['uuid']));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,14 @@ class TenantStorageTest extends TestCase
|
|||
$this->assertFalse(tenant()->all()->contains($abc));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function set_is_a_working_alias_for_put()
|
||||
{
|
||||
tenant()->set('foo', 'bar');
|
||||
|
||||
$this->assertSame('bar', $this->storage->get(tenant('uuid'), 'foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function put_works_with_key_and_value_as_separate_args()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue