From 9bb56c1b302e0baf1bc884e6b07e1b22f75b3597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 18 Sep 2019 18:02:14 +0200 Subject: [PATCH] Fix feature bootstrapping --- src/Features/TenantRedirect.php | 3 +++ src/StorageDrivers/Database/DatabaseStorageDriver.php | 2 +- src/Tenant.php | 3 +++ src/TenantManager.php | 7 +++---- tests/TenantManagerTest.php | 10 +++++++++- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Features/TenantRedirect.php b/src/Features/TenantRedirect.php index 32407dd5..26fb1b08 100644 --- a/src/Features/TenantRedirect.php +++ b/src/Features/TenantRedirect.php @@ -2,6 +2,9 @@ declare(strict_types=1); +namespace Stancl\Tenancy\Features; + +use Illuminate\Http\RedirectResponse; use Stancl\Tenancy\Contracts\Feature; use Stancl\Tenancy\TenantManager; diff --git a/src/StorageDrivers/Database/DatabaseStorageDriver.php b/src/StorageDrivers/Database/DatabaseStorageDriver.php index 5d3c268c..73cd4c8e 100644 --- a/src/StorageDrivers/Database/DatabaseStorageDriver.php +++ b/src/StorageDrivers/Database/DatabaseStorageDriver.php @@ -84,7 +84,7 @@ class DatabaseStorageDriver implements StorageDriver public function updateTenant(Tenant $tenant): void { - Tenant::find($tenant->id)->putMany($tenant->data); + Tenants::find($tenant->id)->putMany($tenant->data); // todo1 update domains } diff --git a/src/Tenant.php b/src/Tenant.php index d5d4f393..1c8cc362 100644 --- a/src/Tenant.php +++ b/src/Tenant.php @@ -269,6 +269,9 @@ class Tenant implements ArrayAccess public function __set($key, $value) { + if ($key === 'id' && isset($this->data['id'])) { + throw new TenantStorageException("Tenant ids can't be changed."); + } $this->data[$key] = $value; } } diff --git a/src/TenantManager.php b/src/TenantManager.php index 7c124cf3..8122a225 100644 --- a/src/TenantManager.php +++ b/src/TenantManager.php @@ -229,10 +229,9 @@ class TenantManager protected function bootstrapFeatures(): self { - // todo1 this doesn't work - // foreach ($this->app['config']['tenancy.features'] as $feature) { - // $this->app[$feature]->bootstrap($this); - // } + foreach ($this->app['config']['tenancy.features'] as $feature) { + $this->app[$feature]->bootstrap($this); + } return $this; } diff --git a/tests/TenantManagerTest.php b/tests/TenantManagerTest.php index e4019376..2a49d78f 100644 --- a/tests/TenantManagerTest.php +++ b/tests/TenantManagerTest.php @@ -205,6 +205,14 @@ class TenantManagerTest extends TestCase /** @test */ public function id_cannot_be_changed() { - // todo1 + $tenant = Tenant::create(['test2.localhost']); + + $this->expectException(\Stancl\Tenancy\Exceptions\TenantStorageException::class); + $tenant->id = 'bar'; + + $tenant2 = Tenant::create(['test3.localhost']); + + $this->expectException(\Stancl\Tenancy\Exceptions\TenantStorageException::class); + $tenant2->put('id', 'foo'); } }