Skip to content

Commit

Permalink
merge published config with package config
Browse files Browse the repository at this point in the history
  • Loading branch information
pxpm authored and freekmurze committed Jan 27, 2025
1 parent 20a40b9 commit f5a238f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public static function fromArray(array $data): self
$source = require dirname(__DIR__, 2).'/config/backup.php';

return new self(
backup: BackupConfig::fromArray(array_merge($source['backup'], $data['backup'] ?? [])),
notifications: NotificationsConfig::fromArray(array_merge($source['notifications'], $data['notifications'] ?? [])),
backup: BackupConfig::fromArray(array_replace_recursive($source['backup'], $data['backup'] ?? [])),
notifications: NotificationsConfig::fromArray(array_replace_recursive($source['notifications'], $data['notifications'] ?? [])),
monitoredBackups: MonitoredBackupsConfig::fromArray($data['monitor_backups'] ?? $source['monitor_backups']),
cleanup: CleanupConfig::fromArray(array_merge($source['cleanup'], $data['cleanup'] ?? []))
cleanup: CleanupConfig::fromArray(array_replace_recursive($source['cleanup'], $data['cleanup'] ?? []))
);
}
}
19 changes: 19 additions & 0 deletions tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Spatie\Backup\Config\BackupConfig;
use Spatie\Backup\Config\CleanupConfig;
use Spatie\Backup\Config\Config;
use Spatie\Backup\Config\DestinationConfig;
use Spatie\Backup\Config\MonitoredBackupsConfig;
use Spatie\Backup\Config\NotificationsConfig;

Expand Down Expand Up @@ -35,3 +36,21 @@

expect($tempDirectory->path())->toBe('/foo');
});

it('merges the published config file with package config file', function () {
config()->set('backup.backup.destination', []);

$config = Config::fromArray(config('backup'));

expect($config->backup->destination)->toBeInstanceOf(DestinationConfig::class);
expect($config->backup->destination->compressionMethod)->toBe(-1);
});

it('merges the published config file with package config file and preserve published config values', function () {
config()->set('backup.backup.destination', ['compression_method' => 2]);

$config = Config::fromArray(config('backup'));

expect($config->backup->destination)->toBeInstanceOf(DestinationConfig::class);
expect($config->backup->destination->compressionMethod)->toBe(2);
});

0 comments on commit f5a238f

Please sign in to comment.