1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 12:54:05 +00:00

Add test for tenancy.database.based_on null

This commit is contained in:
Samuel Štancl 2019-09-21 14:06:42 +02:00
parent c475e7a43d
commit 74aead2a60
3 changed files with 17 additions and 2 deletions

View file

@ -25,7 +25,7 @@ return [
// 'localhost', // 'localhost',
], ],
'database' => [ 'database' => [
'based_on' => null, // The connection that will be used as a base for the dynamically created tenant connection. // todo2 test this 'based_on' => null, // The connection that will be used as a base for the dynamically created tenant connection.
'prefix' => 'tenant', 'prefix' => 'tenant',
'suffix' => '', 'suffix' => '',
], ],

View file

@ -56,7 +56,7 @@ class Migrate extends MigrateCommand
// See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection. // See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection.
// Database connections are cached by Illuminate\Database\ConnectionResolver. // Database connections are cached by Illuminate\Database\ConnectionResolver.
$this->input->setOption('database', 'tenant'); $this->input->setOption('database', 'tenant');
tenancy()->initialize($tenant); // todo2 test that this works with multiple tenants with MySQL tenancy()->initialize($tenant);
// Migrate // Migrate
parent::handle(); parent::handle();

View file

@ -31,4 +31,19 @@ class DatabaseManagerTest extends TestCase
$this->assertSame(config('database.connections.fooconn.database'), database_path('foodb')); $this->assertSame(config('database.connections.fooconn.database'), database_path('foodb'));
} }
/** @test */
public function the_default_db_is_used_when_based_on_is_null()
{
$this->assertSame('sqlite', config('database.default'));
config([
'database.connections.sqlite.foo' => 'bar',
'tenancy.database.based_on' => null,
]);
tenancy()->init('test.localhost');
$this->assertSame('tenant', config('database.default'));
$this->assertSame('bar', config('database.connections.' . config('database.default') . '.foo'));
}
} }