Skip to content

Commit 121943b

Browse files
committed
merge published config with package config
1 parent fe980ce commit 121943b

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Config/Config.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public static function fromArray(array $data): self
2727
$source = require dirname(__DIR__, 2).'/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'] ?? [])),
30+
backup: BackupConfig::fromArray(array_replace_recursive($source['backup'], $data['backup'] ?? [])),
31+
notifications: NotificationsConfig::fromArray(array_replace_recursive($source['notifications'], $data['notifications'] ?? [])),
3232
monitoredBackups: MonitoredBackupsConfig::fromArray($data['monitor_backups'] ?? $source['monitor_backups']),
33-
cleanup: CleanupConfig::fromArray(array_merge($source['cleanup'], $data['cleanup'] ?? []))
33+
cleanup: CleanupConfig::fromArray(array_replace_recursive($source['cleanup'], $data['cleanup'] ?? []))
3434
);
3535
}
3636
}

tests/Config/ConfigTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Spatie\Backup\Config\BackupConfig;
44
use Spatie\Backup\Config\CleanupConfig;
55
use Spatie\Backup\Config\Config;
6+
use Spatie\Backup\Config\DestinationConfig;
67
use Spatie\Backup\Config\MonitoredBackupsConfig;
78
use Spatie\Backup\Config\NotificationsConfig;
89

@@ -35,3 +36,21 @@
3536

3637
expect($tempDirectory->path())->toBe('/foo');
3738
});
39+
40+
it('merges the published config file with package config file', function () {
41+
config()->set('backup.backup.destination', []);
42+
43+
$config = Config::fromArray(config('backup'));
44+
45+
expect($config->backup->destination)->toBeInstanceOf(DestinationConfig::class);
46+
expect($config->backup->destination->compressionMethod)->toBe(-1);
47+
});
48+
49+
it('merges the published config file with package config file and preserve published config values', function () {
50+
config()->set('backup.backup.destination', ['compression_method' => 2]);
51+
52+
$config = Config::fromArray(config('backup'));
53+
54+
expect($config->backup->destination)->toBeInstanceOf(DestinationConfig::class);
55+
expect($config->backup->destination->compressionMethod)->toBe(2);
56+
});

0 commit comments

Comments
 (0)