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.
76 lines
3.3 KiB
PHP
76 lines
3.3 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');
|
|
$controller = file_get_contents(
|
|
dirname(__DIR__) . '/app/Controllers/CloudApiController.php'
|
|
);
|
|
$middleware = file_get_contents(dirname(__DIR__) . '/app/Middleware/CloudApi.php');
|
|
$automaticService = file_get_contents(
|
|
dirname(__DIR__) . '/app/Services/Cloud/CloudAutomaticBackupService.php'
|
|
);
|
|
$backupService = file_get_contents(
|
|
dirname(__DIR__) . '/app/Services/Cloud/CloudBackupService.php'
|
|
);
|
|
$assert(str_contains($routes, "'/backups'")
|
|
&& str_contains($routes, "'/vms/{id:[0-9]+}/automatic-backup'")
|
|
&& str_contains($routes,
|
|
"'/vms/{id:[0-9]+}/automatic-backup/enable'")
|
|
&& str_contains($routes,
|
|
"'/vms/{id:[0-9]+}/automatic-backup/disable'")
|
|
&& str_contains($routes,
|
|
"'/vms/{id:[0-9]+}/automatic-backup/{backup_id:[0-9]+}/restore'"),
|
|
'Owner backup routes are incomplete.');
|
|
$assert(str_contains($controller, 'CloudAutomaticBackupBillingService::enable(')
|
|
&& str_contains($controller, 'CloudAutomaticBackupBillingService::disable(')
|
|
&& str_contains($controller, '$value[\'billing\'] =')
|
|
&& str_contains($controller, "'entitlement_paid_until' =>"),
|
|
'Owner backup API does not expose the paid toggle and billing state.');
|
|
$assert(str_contains($middleware,
|
|
"#^/api/v1/vms/[0-9]+/automatic-backup(?:/(?:enable|disable))?$#D")
|
|
&& !str_contains($middleware,
|
|
'automatic-backup(?:/|$)'),
|
|
'Database-only backup routes are missing or incorrectly include restore.');
|
|
$assert(str_contains($automaticService,
|
|
'CloudBackupPeriodEntitlement::where(')
|
|
&& str_contains($automaticService,
|
|
'->where(\'starts_at\', \'<=\', $scheduledFor)')
|
|
&& str_contains($backupService,
|
|
'CloudBackupPeriodEntitlement::where(')
|
|
&& str_contains($backupService,
|
|
'->where(\'ends_at\', \'>\', $scheduledFor)')
|
|
&& !str_contains($backupService,
|
|
'($spec[\'automatic_backup\'] ?? null) !== true'),
|
|
'Automatic backup scheduling is not guarded by paid-period entitlement on both sides of the transaction.');
|
|
|
|
echo "Automatic backup Pacific schedule and route contract passed.\n";
|