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")); + } }