diff --git a/src/Config/Config.php b/src/Config/Config.php index 78f9787b..8a34ea45 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -24,11 +24,13 @@ public static function rebind(): void /** @param array $data */ public static function fromArray(array $data): self { + $source = require realpath(__DIR__.'/../../config/backup.php'); + return new self( - backup: BackupConfig::fromArray($data['backup']), - notifications: NotificationsConfig::fromArray($data['notifications']), - monitoredBackups: MonitoredBackupsConfig::fromArray($data['monitor_backups']), - cleanup: CleanupConfig::fromArray($data['cleanup']), + backup: BackupConfig::fromArray(array_merge($source['backup'], $data['backup'] ?? [])), + notifications: NotificationsConfig::fromArray(array_merge($source['notifications'], $data['notifications'] ?? [])), + monitoredBackups: MonitoredBackupsConfig::fromArray($data['monitor_backups'] ?? $source['monitor_backups']), + cleanup: CleanupConfig::fromArray(array_merge($source['cleanup'], $data['cleanup'] ?? [])) ); } } diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php new file mode 100644 index 00000000..e6a6cbbc --- /dev/null +++ b/tests/Config/ConfigTest.php @@ -0,0 +1,29 @@ +set('backup', []); +}); + +it('returns default backup config if no backup config file exist', function () { + $config = Config::fromArray(config('backup')); + + expect($config->backup)->toBeInstanceOf(BackupConfig::class); + expect($config->notifications)->toBeInstanceOf(NotificationsConfig::class); + expect($config->monitoredBackups)->toBeInstanceOf(MonitoredBackupsConfig::class); + expect($config->cleanup)->toBeInstanceOf(CleanupConfig::class); +}); + +it('returns a merged backup config made with minimal config and default config file', function () { + config()->set('backup.backup.name', 'foo'); + + $config = Config::fromArray(config('backup')); + + expect($config->backup)->toBeInstanceOf(BackupConfig::class); + expect($config->backup->name)->toBe('foo'); +});