From 65b2c6ceeee1a52c3c645337e0e197903fdfad63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Fri, 20 Sep 2019 16:57:53 +0200 Subject: [PATCH] Null connection test --- assets/config.php | 2 +- tests/TenancyBootstrappersTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/assets/config.php b/assets/config.php index 66b9a39e..c42dd34b 100644 --- a/assets/config.php +++ b/assets/config.php @@ -10,7 +10,7 @@ return [ 'custom_columns' => [ // 'plan', ], - 'connection' => null, // todo verify this works + 'connection' => null, 'table_names' => [ 'TenantModel' => 'tenants', 'DomainModel' => 'domains', diff --git a/tests/TenancyBootstrappersTest.php b/tests/TenancyBootstrappersTest.php index df18128d..ad719dfc 100644 --- a/tests/TenancyBootstrappersTest.php +++ b/tests/TenancyBootstrappersTest.php @@ -77,4 +77,20 @@ class TenancyBootstrappersTest extends TestCase $expected = [config('tenancy.cache.tag_base') . tenant('id'), 'foo', 'bar']; $this->assertEquals($expected, cache()->tags(['foo', 'bar'])->getTags()->getNames()); } + + /** @test */ + public function the_default_db_connection_is_used_when_the_config_value_is_null() + { + $original = config('database.default'); + tenancy()->create(['foo.localhost']); + tenancy()->init('foo.localhost'); + + $this->assertSame(null, config("database.connections.$original.foo")); + + config(["database.connections.$original.foo" => 'bar']); + tenancy()->create(['bar.localhost']); + tenancy()->init('bar.localhost'); + + $this->assertSame('bar', config("database.connections.$original.foo")); + } }