You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudAutomaticBackupSchedul...

41 lines
1.6 KiB
PHP

<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Services\Cloud\CloudAutomaticBackupService;
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
// America/Los_Angeles changes from PST to PDT between these two local
// midnights. The UTC interval is 23 hours, while the user-facing run time
// remains exactly 00:00 Pacific.
$beforeDst = strtotime('2026-03-08T07:30:00Z');
$first = CloudAutomaticBackupService::nextRunAt($beforeDst, 'daily', 0);
$second = CloudAutomaticBackupService::nextRunAt($first, 'daily', 0);
$assert(gmdate('Y-m-d H:i:s', $first) === '2026-03-08 08:00:00'
&& gmdate('Y-m-d H:i:s', $second) === '2026-03-09 07:00:00'
&& $second - $first === 23 * 3600,
'Pacific midnight drifted across the spring daylight-saving transition.');
$weekly = CloudAutomaticBackupService::nextRunAt(
strtotime('2026-10-24T19:00:00Z'), 'weekly', 1
);
$local = (new DateTimeImmutable('@' . $weekly))->setTimezone(
new DateTimeZone(CloudAutomaticBackupService::TIMEZONE)
);
$assert($local->format('w H:i') === '1 00:00',
'Weekly schedule did not use the selected Pacific weekday at midnight.');
$routes = file_get_contents(dirname(__DIR__) . '/config/routes_cloud.php');
$assert(str_contains($routes, "'/backups'")
&& str_contains($routes, "'/vms/{id:[0-9]+}/automatic-backup'")
&& str_contains($routes,
"'/vms/{id:[0-9]+}/automatic-backup/{backup_id:[0-9]+}/restore'"),
'Owner backup routes are incomplete.');
echo "Automatic backup Pacific schedule and route contract passed.\n";