From 8d382024a36c280f2eb3940abbb9dd6a92f9abd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 9 Feb 2019 00:17:51 +0100 Subject: [PATCH] Add more TenantManager tests --- src/TenantManager.php | 19 ++++++-------- tests/TenantManagerTest.php | 50 ++++++++++++++++++++++++++++++++++++- tests/TenantStorageTest.php | 8 ++++++ 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/src/TenantManager.php b/src/TenantManager.php index b952499e..dcc75fa1 100644 --- a/src/TenantManager.php +++ b/src/TenantManager.php @@ -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. * diff --git a/tests/TenantManagerTest.php b/tests/TenantManagerTest.php index e350427c..b1a5fece 100644 --- a/tests/TenantManagerTest.php +++ b/tests/TenantManagerTest.php @@ -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'])); + } } diff --git a/tests/TenantStorageTest.php b/tests/TenantStorageTest.php index 8962f96e..ac2fe03d 100644 --- a/tests/TenantStorageTest.php +++ b/tests/TenantStorageTest.php @@ -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() {