mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 07:54:03 +00:00
Write test for extra config, fix bug with extra config
This commit is contained in:
parent
dfefe77793
commit
bfa62a3f0c
3 changed files with 58 additions and 8 deletions
|
|
@ -125,13 +125,18 @@ class DatabaseConfig
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove DB name because we set that separately
|
// Remove DB name because we set that separately
|
||||||
if (isset($dbConfig['_tenancy_db_name'])) {
|
if (($pos = array_search('_tenancy_db_name', $dbConfig)) !== false) {
|
||||||
unset($dbConfig['_tenancy_db_name']);
|
unset($dbConfig[$pos]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove DB connection because that's not used inside the array
|
||||||
|
if (($pos = array_search('_tenancy_db_connection', $dbConfig)) !== false) {
|
||||||
|
unset($dbConfig[$pos]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_reduce($dbConfig, function ($config, $key) {
|
return array_reduce($dbConfig, function ($config, $key) {
|
||||||
return array_merge($config, [
|
return array_merge($config, [
|
||||||
Str::substr($key, 0, strlen('_tenancy_db_')) => $this->tenant[$key],
|
Str::substr($key, strlen('_tenancy_db_')) => $this->tenant[$key],
|
||||||
]);
|
]);
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,4 @@ class DatabaseManagerTest extends TestCase
|
||||||
|
|
||||||
tenancy()->all()->each->delete();
|
tenancy()->all()->each->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
|
||||||
public function extra_config_is_merged_into_the_connection_config_array()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -174,4 +174,54 @@ class TenantClassTest extends TestCase
|
||||||
return $tenant->id;
|
return $tenant->id;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function extra_config_is_merged_into_the_connection_config_array()
|
||||||
|
{
|
||||||
|
$tenant = Tenant::new()->withData([
|
||||||
|
'_tenancy_db_link' => 'foo',
|
||||||
|
'_tenancy_db_name' => 'dbname',
|
||||||
|
'_tenancy_db_username' => 'usernamefoo',
|
||||||
|
'_tenancy_db_password' => 'passwordfoo',
|
||||||
|
'_tenancy_db_connection' => 'mysql',
|
||||||
|
]);
|
||||||
|
|
||||||
|
config(['database.connections.mysql' => [
|
||||||
|
"driver" => "mysql",
|
||||||
|
"url" => null,
|
||||||
|
"host" => "mysql",
|
||||||
|
"port" => "3306",
|
||||||
|
"database" => "main",
|
||||||
|
"username" => "root",
|
||||||
|
"password" => "password",
|
||||||
|
"unix_socket" => "",
|
||||||
|
"charset" => "utf8mb4",
|
||||||
|
"collation" => "utf8mb4_unicode_ci",
|
||||||
|
"prefix" => "",
|
||||||
|
"prefix_indexes" => true,
|
||||||
|
"strict" => true,
|
||||||
|
"engine" => null,
|
||||||
|
"options" => [],
|
||||||
|
]]);
|
||||||
|
|
||||||
|
$this->assertEquals([
|
||||||
|
'database' => 'dbname',
|
||||||
|
'username' => 'usernamefoo',
|
||||||
|
'password' => 'passwordfoo',
|
||||||
|
'link' => 'foo',
|
||||||
|
|
||||||
|
"driver" => "mysql",
|
||||||
|
"url" => null,
|
||||||
|
"host" => "mysql",
|
||||||
|
"port" => "3306",
|
||||||
|
"unix_socket" => "",
|
||||||
|
"charset" => "utf8mb4",
|
||||||
|
"collation" => "utf8mb4_unicode_ci",
|
||||||
|
"prefix" => "",
|
||||||
|
"prefix_indexes" => true,
|
||||||
|
"strict" => true,
|
||||||
|
"engine" => null,
|
||||||
|
"options" => [],
|
||||||
|
], $tenant->database()->connection());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue