39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
require_once __DIR__ . '/../app/Domain/Client/ClientContactValidator.php';
|
||
|
|
|
||
|
|
$invalid = validate_client_contact([
|
||
|
|
'name' => ' ',
|
||
|
|
'email' => 'not-an-email',
|
||
|
|
'phone' => str_repeat('1', 61),
|
||
|
|
'is_primary' => 'maybe',
|
||
|
|
]);
|
||
|
|
foreach (['name', 'email', 'phone', 'is_primary'] as $key) {
|
||
|
|
if (!isset($invalid['errors'][$key])) {
|
||
|
|
throw new RuntimeException("Expected validation error for {$key}");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$valid = validate_client_contact([
|
||
|
|
'name' => ' Jane Doe ',
|
||
|
|
'email' => ' JANE@example.com ',
|
||
|
|
'phone' => ' +27 11 555 0100 ',
|
||
|
|
'is_primary' => '1',
|
||
|
|
]);
|
||
|
|
if ($valid['errors'] !== []
|
||
|
|
|| $valid['name'] !== 'Jane Doe'
|
||
|
|
|| $valid['email'] !== 'jane@example.com'
|
||
|
|
|| $valid['phone'] !== '+27 11 555 0100'
|
||
|
|
|| $valid['is_primary'] !== true
|
||
|
|
) {
|
||
|
|
throw new RuntimeException('Expected contact input to be normalized');
|
||
|
|
}
|
||
|
|
|
||
|
|
$optional = normalize_client_contact(['name' => 'Sam']);
|
||
|
|
if ($optional !== ['name' => 'Sam', 'email' => null, 'phone' => null, 'is_primary' => false]) {
|
||
|
|
throw new RuntimeException('Expected optional contact fields to normalize to null/defaults');
|
||
|
|
}
|
||
|
|
|
||
|
|
printf("Client contact validator tests: 3 passed\n");
|