From b33366e0c09f5cf51dab3f7fa1bb974ff802b75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?michael=20lundb=C3=B8l?= Date: Sat, 24 Oct 2020 16:53:37 +0200 Subject: [PATCH] Improve the tests for central helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: michael lundbøl --- tests/AutomaticModeTest.php | 40 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/tests/AutomaticModeTest.php b/tests/AutomaticModeTest.php index 2371fb75..8bcd979a 100644 --- a/tests/AutomaticModeTest.php +++ b/tests/AutomaticModeTest.php @@ -75,9 +75,6 @@ class AutomaticModeTest extends TestCase /** @test */ public function running_the_central_tenancy_helper_with_tenant_already_initialized() { - MyBootstrapper::$revertedCallCount = 0; - GlobalRun::$count = 0; - config(['tenancy.bootstrappers' => [ MyBootstrapper::class, ]]); @@ -91,38 +88,44 @@ class AutomaticModeTest extends TestCase $this->assertSame('acme', app('tenancy_initialized_for_tenant')); tenancy()->central(function () { - GlobalRun::$count = 1; + $this->assertTrue(app('tenancy_ended')); + $this->assertEmpty(app('tenancy_initialized_for_tenant')); }); - $this->assertSame(1, MyBootstrapper::$revertedCallCount); - $this->assertSame(1, GlobalRun::$count); $this->assertSame('acme', app('tenancy_initialized_for_tenant')); } /** @test */ public function running_the_central_tenancy_helper_with_tenant_not_already_initialized() { - MyBootstrapper::$revertedCallCount = 0; - GlobalRun::$count = 0; - config(['tenancy.bootstrappers' => [ MyBootstrapper::class, ]]); - tenancy()->central(function () { - GlobalRun::$count = 1; + $runned = 0; + + $this->assertFalse(tenancy()->initialized); + $this->assertFalse(app()->bound('tenancy_ended')); + $this->assertFalse(app()->bound('tenancy_initialized_for_tenant')); + + tenancy()->central(function () use (&$runned) { + $this->assertFalse(app()->bound('tenancy_initialized_for_tenant')); + $this->assertFalse(app()->bound('tenancy_ended')); + $this->assertFalse(tenancy()->initialized); + + $runned = 1; }); - $this->assertSame(0, MyBootstrapper::$revertedCallCount); - $this->assertSame(1, GlobalRun::$count); + $this->assertSame(1, $runned); + + $this->assertFalse(app()->bound('tenancy_ended')); $this->assertFalse(app()->bound('tenancy_initialized_for_tenant')); + $this->assertFalse(tenancy()->initialized); } } class MyBootstrapper implements TenancyBootstrapper { - public static $revertedCallCount = 0; - public function bootstrap(\Stancl\Tenancy\Contracts\Tenant $tenant) { app()->instance('tenancy_initialized_for_tenant', $tenant->getTenantKey()); @@ -130,12 +133,7 @@ class MyBootstrapper implements TenancyBootstrapper public function revert() { - static::$revertedCallCount++; + app()->instance('tenancy_initialized_for_tenant', ''); app()->instance('tenancy_ended', true); } } - -class GlobalRun { - - public static $count = 0; -}