mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:24:03 +00:00
By default, only override the config if the override tenant property is set (otherwise, just skip the override and keep the default config value)
This commit is contained in:
parent
582243c53f
commit
bd44036a9f
2 changed files with 17 additions and 1 deletions
|
|
@ -100,8 +100,10 @@ class LogTenancyBootstrapper implements TenancyBootstrapper
|
|||
if (is_array($override)) {
|
||||
// Map tenant properties to channel config keys
|
||||
foreach ($override as $configKey => $tenantProperty) {
|
||||
if ($tenant->$tenantProperty) {
|
||||
$this->config->set("logging.channels.{$channel}.{$configKey}", $tenant->$tenantProperty);
|
||||
}
|
||||
}
|
||||
} elseif ($override instanceof Closure) {
|
||||
// Execute custom configuration closure
|
||||
$override($this->config, $tenant);
|
||||
|
|
|
|||
|
|
@ -150,6 +150,20 @@ test('channel overrides work correctly with both arrays and closures', function
|
|||
expect(config('logging.channels.slack.username'))->toBe('Default');
|
||||
});
|
||||
|
||||
test('channel config keys remains unchanged if the specified tenant override property is not set', function() {
|
||||
config(['logging.default' => 'slack']);
|
||||
config(['logging.channels.slack.username' => 'Default username']);
|
||||
|
||||
LogTenancyBootstrapper::$channelOverrides = [
|
||||
'slack' => ['username' => 'nonExistentProperty'], // $tenant->nonExistentProperty
|
||||
];
|
||||
|
||||
tenancy()->initialize(Tenant::create());
|
||||
|
||||
// The username should remain unchanged since the tenant property is not set
|
||||
expect(config('logging.channels.slack.username'))->toBe('Default username');
|
||||
});
|
||||
|
||||
test('channel overrides take precedence over the default storage path channel updating logic', function () {
|
||||
config(['logging.default' => 'single']);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue