Files
JobcardSystem/tests/SlaDomainTest.php
T

19 lines
1010 B
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../app/Domain/SLA/SlaThresholdClassifier.php';
require_once __DIR__ . '/../app/Domain/SLA/SlaCalculator.php';
use App\Domain\SLA\SlaThresholdClassifier;
$negativeRejected = false;
try { calculate_sla_usage(-1.0, [1.0]); } catch (InvalidArgumentException $exception) { $negativeRejected = true; }
if (!$negativeRejected) throw new RuntimeException('Negative SLA allocation must be rejected');
$classifier = new SlaThresholdClassifier();
if ($classifier->classify(7.5, 10.0) !== 'warning') throw new RuntimeException('75% should be warning.');
if ($classifier->classify(9.0, 10.0) !== 'critical') throw new RuntimeException('90% should be critical.');
if ($classifier->classify(10.01, 10.0) !== 'exceeded') throw new RuntimeException('Over allocation should be exceeded.');
if ($classifier->classify(0.0, 0.0) !== 'within_limit') throw new RuntimeException('No allocation and no usage should be within limit.');
printf("SLA domain tests: 4 passed\n");