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/CloudServiceCompensationMod...

65 lines
2.5 KiB
PHP

<?php
$root = dirname(__DIR__);
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$models = [
'CloudServiceCompensation.php' => [
'cloud_service_compensations',
[
'requested_by_user_id', 'scope_id', 'incident_starts_at',
'incident_ends_at', 'compensation_seconds', 'notify_users',
'instance_count', 'recipient_count', 'applied_count',
'deferred_count', 'rejected_count', 'attention_count',
'terminal_at', 'created_at', 'updated_at',
],
],
'CloudServiceCompensationItem.php' => [
'cloud_service_compensation_items',
[
'batch_id', 'instance_id', 'user_id', 'host_id',
'requested_seconds', 'service_period_id',
'traffic_entitlement_id', 'backup_entitlement_id',
'source_invoice_id', 'replacement_invoice_id', 'audit_job_id',
'before_expires_at', 'after_expires_at',
'before_period_ends_at', 'after_period_ends_at',
'before_traffic_ends_at', 'after_traffic_ends_at',
'before_backup_ends_at', 'after_backup_ends_at', 'attempts',
'available_at', 'lease_until', 'applied_at', 'terminal_at',
],
],
'CloudServiceCompensationRecipient.php' => [
'cloud_service_compensation_recipients',
[
'batch_id', 'user_id', 'instance_count', 'attempts',
'available_at', 'lease_until', 'sent_at', 'created_at',
'updated_at',
],
],
];
foreach ($models as $file => [$table, $casts]) {
$source = file_get_contents($root . '/app/Models/' . $file);
$assert(str_contains($source, "protected \$connection = 'default';"),
$file . ' does not use the default business connection.');
$assert(str_contains($source, "protected \$table = '" . $table . "';"),
$file . ' does not bind the expected table.');
foreach ($casts as $cast) {
$assert(str_contains($source, "'" . $cast . "' =>"),
$file . ' is missing cast ' . $cast . '.');
}
foreach ([
'scope_snapshot_json', 'before_snapshot_json',
'after_snapshot_json', 'payload_json',
] as $jsonColumn) {
$assert(!str_contains($source, "'" . $jsonColumn . "' => 'array'"),
$file . ' must retain canonical JSON string ' . $jsonColumn . '.');
}
}
echo "Service compensation model contracts passed.\n";