Skip to content

Commit 358076f

Browse files
committed
merge default backup config with user config
1 parent 6358d30 commit 358076f

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/Config/Config.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public static function fromArray(array $data): self
2727
$source = require realpath(__DIR__.'/../../config/backup.php');
2828

2929
return new self(
30-
backup: BackupConfig::fromArray(array_merge($source['backup'], $data['backup'])),
31-
notifications: NotificationsConfig::fromArray(array_merge($source['notifications'], $data['notifications'])),
32-
monitoredBackups: MonitoredBackupsConfig::fromArray($data['monitor_backups'] ?? $source['notifications']),
33-
cleanup: CleanupConfig::fromArray(array_merge($source['cleanup'], $data['cleanup']))
30+
backup: BackupConfig::fromArray(array_merge($source['backup'], $data['backup'] ?? [])),
31+
notifications: NotificationsConfig::fromArray(array_merge($source['notifications'], $data['notifications'] ?? [])),
32+
monitoredBackups: MonitoredBackupsConfig::fromArray($data['monitor_backups'] ?? $source['monitor_backups']),
33+
cleanup: CleanupConfig::fromArray(array_merge($source['cleanup'], $data['cleanup'] ?? []))
3434
);
3535
}
3636
}

tests/ConfigTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Spatie\Backup\Config\Config;
4+
use Spatie\Backup\Config\BackupConfig;
5+
use Spatie\Backup\Config\NotificationsConfig;
6+
use Spatie\Backup\Config\MonitoredBackupsConfig;
7+
use Spatie\Backup\Config\CleanupConfig;
8+
9+
beforeEach(function () {
10+
config()->set('backup', []);
11+
});
12+
13+
it('returns default backup config if no backup config file exist', function () {
14+
$config = Config::fromArray(config('backup'));
15+
16+
expect($config->backup)->toBeInstanceOf(BackupConfig::class);
17+
expect($config->notifications)->toBeInstanceOf(NotificationsConfig::class);
18+
expect($config->monitoredBackups)->toBeInstanceOf(MonitoredBackupsConfig::class);
19+
expect($config->cleanup)->toBeInstanceOf(CleanupConfig::class);
20+
});
21+
22+
it('returns a merged backup config made with minimal config and default config file', function () {
23+
config()->set('backup.backup.name', 'foo');
24+
25+
$config = Config::fromArray(config('backup'));
26+
27+
expect($config->backup)->toBeInstanceOf(BackupConfig::class);
28+
expect($config->backup->name)->toBe('foo');
29+
});

0 commit comments

Comments
 (0)