2026-09-01 18:54:47 +02:00
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../app/Domain/Jobcard/TimeCalculator.php';
|
|
|
|
|
require_once __DIR__ . '/../app/Domain/SLA/SlaCalculator.php';
|
|
|
|
|
|
|
|
|
|
if (calculate_duration_hours('09:00', '11:30') !== 2.5) {
|
|
|
|
|
throw new RuntimeException('Expected 2.5 hours from start/end');
|
|
|
|
|
}
|
|
|
|
|
if (calculate_duration_hours(null, null, 1.25) !== 1.25) {
|
|
|
|
|
throw new RuntimeException('Expected manual duration');
|
|
|
|
|
}
|
|
|
|
|
if (calculate_duration_hours('11:30', '09:00') !== null) {
|
|
|
|
|
throw new RuntimeException('Expected invalid reverse time to be rejected');
|
|
|
|
|
}
|
2026-09-01 18:58:18 +02:00
|
|
|
if (calculate_duration_hours(null, null, 0.0) !== null) {
|
|
|
|
|
throw new RuntimeException('Expected zero manual hours to be rejected');
|
|
|
|
|
}
|
2026-09-01 18:54:47 +02:00
|
|
|
$sla = calculate_sla_usage(20.0, [2.0, 1.5, 1.0]);
|
|
|
|
|
if ($sla !== ['used' => 4.5, 'remaining' => 15.5, 'percentage' => 22.5, 'status' => 'within_limit']) {
|
|
|
|
|
throw new RuntimeException('Unexpected SLA calculation: ' . json_encode($sla));
|
|
|
|
|
}
|
|
|
|
|
$over = calculate_sla_usage(10.0, [8.0, 4.0]);
|
|
|
|
|
if ($over['status'] !== 'exceeded' || $over['remaining'] !== 0.0) {
|
|
|
|
|
throw new RuntimeException('Expected exceeded SLA to clamp remaining hours to zero');
|
|
|
|
|
}
|
|
|
|
|
printf("Jobcard calculation tests: 5 passed\n");
|