From 0111ed6f53bab7baccfa12dc48cda360acb1d016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 14 Aug 2019 16:54:49 +0200 Subject: [PATCH] Fix typos, add tests --- src/Traits/BootstrapsTenancy.php | 4 ++-- src/Traits/TenantManagerEvents.php | 6 +++--- tests/TenantManagerTest.php | 31 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/Traits/BootstrapsTenancy.php b/src/Traits/BootstrapsTenancy.php index e5be25ac..cbfd9465 100644 --- a/src/Traits/BootstrapsTenancy.php +++ b/src/Traits/BootstrapsTenancy.php @@ -23,7 +23,7 @@ trait BootstrapsTenancy { array_map(function ($listener) { $listener($this); - }, $this->listeners['boostrapping']); + }, $this->listeners['bootstrapping']); $this->initialized = true; @@ -36,7 +36,7 @@ trait BootstrapsTenancy array_map(function ($listener) { $listener($this); - }, $this->listeners['boostrapped']); + }, $this->listeners['bootstrapped']); } public function end() diff --git a/src/Traits/TenantManagerEvents.php b/src/Traits/TenantManagerEvents.php index cc9f9e7c..0094b888 100644 --- a/src/Traits/TenantManagerEvents.php +++ b/src/Traits/TenantManagerEvents.php @@ -10,8 +10,8 @@ trait TenantManagerEvents * @var callable[][] */ protected $listeners = [ - 'boostrapping' => [], - 'boostrapped' => [], + 'bootstrapping' => [], + 'bootstrapped' => [], 'ending' => [], 'ended' => [], ]; @@ -35,7 +35,7 @@ trait TenantManagerEvents * @param callable $callback * @return self */ - public function boostrapped(callable $callback) + public function bootstrapped(callable $callback) { $this->listeners['bootstrapped'][] = $callback; diff --git a/tests/TenantManagerTest.php b/tests/TenantManagerTest.php index 453730ea..e05c4ef2 100644 --- a/tests/TenantManagerTest.php +++ b/tests/TenantManagerTest.php @@ -2,6 +2,7 @@ namespace Stancl\Tenancy\Tests; +use Tenancy; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Stancl\Tenancy\Exceptions\CannotChangeUuidOrDomainException; @@ -241,4 +242,34 @@ class TenantManagerTest extends TestCase $this->expectException(CannotChangeUuidOrDomainException::class); tenant()->put(['uuid' => 'foo']); } + + /** @test */ + public function bootstrapping_event_works() + { + $uuid = tenant()->create('foo.localhost')['uuid']; + + Tenancy::bootstrapping(function ($tenantManager) use ($uuid) { + if ($tenantManager->tenant['uuid'] === $uuid) { + config(['tenancy.foo' => 'bar']); + } + }); + + tenancy()->init('foo.localhost'); + $this->assertSame('bar', config('tenancy.foo')); + } + + /** @test */ + public function bootstrapped_event_works() + { + $uuid = tenant()->create('foo.localhost')['uuid']; + + Tenancy::bootstrapped(function ($tenantManager) use ($uuid) { + if ($tenantManager->tenant['uuid'] === $uuid) { + config(['tenancy.foo' => 'bar']); + } + }); + + tenancy()->init('foo.localhost'); + $this->assertSame('bar', config('tenancy.foo')); + } }