From 3857c4a27d48f86a226d386a408c87bca5d6d2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Thu, 7 Feb 2019 22:28:41 +0100 Subject: [PATCH] Add TestCase@initTenancy --- tests/BootstrapsTenancyTest.php | 6 +++--- tests/TestCase.php | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/BootstrapsTenancyTest.php b/tests/BootstrapsTenancyTest.php index 8beaf506..ec31d4ea 100644 --- a/tests/BootstrapsTenancyTest.php +++ b/tests/BootstrapsTenancyTest.php @@ -12,7 +12,7 @@ class BootstrapsTenancyTest extends TestCase public function database_connection_is_switched() { $old_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName(); - tenancy()->init('localhost'); + $this->initTenancy(); $new_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName(); $this->assertNotEquals($old_connection_name, $new_connection_name); @@ -22,7 +22,7 @@ class BootstrapsTenancyTest extends TestCase /** @test */ public function redis_is_prefixed() { - tenancy()->init('localhost'); + $this->initTenancy(); foreach (config('tenancy.redis.prefixed_connections', ['default']) as $connection) { $prefix = config('tenancy.redis.prefix_base') . tenant('uuid'); $client = Redis::connection($connection)->client(); @@ -34,7 +34,7 @@ class BootstrapsTenancyTest extends TestCase public function filesystem_is_suffixed() { $old_storage_path = storage_path(); - tenancy()->init(); + $this->initTenancy(); $new_storage_path = storage_path(); $this->assertEquals($old_storage_path . "/" . config('tenancy.filesystem.suffix_base') . tenant('uuid'), $new_storage_path); diff --git a/tests/TestCase.php b/tests/TestCase.php index a5bd1aa4..9312b19b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -16,7 +16,7 @@ class TestCase extends \Orchestra\Testbench\TestCase protected function setUp() { parent::setUp(); - + Redis::connection('tenancy')->flushdb(); tenant()->create('localhost'); @@ -84,4 +84,9 @@ class TestCase extends \Orchestra\Testbench\TestCase // set one of these environment vars on their computer. return env('CI') && env('TRAVIS') && env('CONTINUOUS_INTEGRATION'); } + + public function initTenancy($domain = 'localhost') + { + tenancy()->init($domain); + } }