Files
JobcardSystem/tests/ClientValidatorTest.php
T

30 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../app/Domain/Client/ClientValidator.php';
require_once __DIR__ . '/../app/Domain/Client/ClientHelpers.php';
$cases = [
[[], 'name'],
[['name' => str_repeat('A', 191)], 'name'],
[['name' => 'Acme', 'status' => 'paused'], 'status'],
];
foreach ($cases as [$input, $errorKey]) {
$result = validate_client($input);
if (!isset($result['errors'][$errorKey])) {
throw new RuntimeException("Expected validation error for {$errorKey}");
}
}
$valid = validate_client(['name' => ' Acme IT ', 'status' => 'active']);
if ($valid['errors'] !== [] || $valid['name'] !== 'Acme IT') {
throw new RuntimeException('Expected valid client input to be normalized');
}
if (!client_name_is_duplicate(' acme IT ', ['Acme IT', 'Other'])) {
throw new RuntimeException('Expected duplicate client names to be detected case-insensitively');
}
if (client_name_is_duplicate('New Client', ['Acme IT'])) {
throw new RuntimeException('Expected unique client name to be accepted');
}
printf("Client validator tests: %d passed\n", count($cases) + 2);