From 8beaaaeda71c4da83e2aba77482a98114f4f3ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Fri, 20 Sep 2019 17:05:19 +0200 Subject: [PATCH] ensureTenantCanBeCreated test --- .../Database/DatabaseStorageDriver.php | 4 ++-- tests/TenantManagerTest.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/StorageDrivers/Database/DatabaseStorageDriver.php b/src/StorageDrivers/Database/DatabaseStorageDriver.php index baebafa7..a989400b 100644 --- a/src/StorageDrivers/Database/DatabaseStorageDriver.php +++ b/src/StorageDrivers/Database/DatabaseStorageDriver.php @@ -7,7 +7,7 @@ namespace Stancl\Tenancy\StorageDrivers\Database; use Illuminate\Foundation\Application; use Illuminate\Support\Facades\DB; use Stancl\Tenancy\Contracts\StorageDriver; -use Stancl\Tenancy\Exceptions\DomainOccupiedByOtherTenantException; +use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException; use Stancl\Tenancy\Exceptions\TenantWithThisIdAlreadyExistsException; use Stancl\Tenancy\StorageDrivers\Database\DomainModel as Domains; @@ -60,7 +60,7 @@ class DatabaseStorageDriver implements StorageDriver } if (Domains::whereIn('domain', $tenant->domains)->exists()) { - throw new DomainOccupiedByOtherTenantException(); + throw new DomainsOccupiedByOtherTenantException; } } diff --git a/tests/TenantManagerTest.php b/tests/TenantManagerTest.php index c1c54511..18723920 100644 --- a/tests/TenantManagerTest.php +++ b/tests/TenantManagerTest.php @@ -6,6 +6,8 @@ namespace Stancl\Tenancy\Tests; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; +use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException; +use Stancl\Tenancy\Exceptions\TenantWithThisIdAlreadyExistsException; use Stancl\Tenancy\Tenant; use Stancl\Tenancy\TenantManager; @@ -230,4 +232,16 @@ class TenantManagerTest extends TestCase tenancy()->initialize($tenant2); $this->assertTrue(\Schema::hasTable('users')); } + + /** @test */ + public function ensureTenantCanBeCreated_works() + { + $id = 'foo' . $this->randomString(); + Tenant::create(['foo.localhost'], ['id' => $id]); + $this->expectException(DomainsOccupiedByOtherTenantException::class); + Tenant::create(['foo.localhost']); + + $this->expectException(TenantWithThisIdAlreadyExistsException::class); + Tenant::create(['bar.localhost'], ['id' => $id]); + } }