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/CloudCountryCatalogTest.php

41 lines
1.5 KiB
PHTML

<?php
use App\Services\Cloud\CloudCountryCatalog;
use App\Services\Cloud\CloudError;
require dirname(__DIR__) . '/app/Services/Cloud/CloudError.php';
require dirname(__DIR__) . '/app/Services/Cloud/CloudCountryCatalog.php';
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$options = CloudCountryCatalog::options();
$codes = array_column($options, 'code');
$assert($codes === ['CN', 'HK', 'JP', 'US', 'SG'],
'Country options must remain ordered, explicit and unique.');
$assert(CloudCountryCatalog::normalize(' jp ') === 'JP',
'Country normalization must trim and uppercase a complete code.');
foreach (['JPN', 'ZZ', '', null, 81] as $invalid) {
try {
CloudCountryCatalog::normalize($invalid);
throw new RuntimeException('Invalid country input was accepted: ' . var_export($invalid, true));
} catch (CloudError $error) {
$assert($error->httpStatus === 422,
'Invalid country input must remain a validation error.');
}
}
$known = CloudCountryCatalog::option('hk');
$assert($known['code'] === 'HK' && $known['name'] === '中国香港'
&& $known['flag'] === '🇭🇰',
'Known country metadata did not round-trip through the shared catalog.');
$unsupported = CloudCountryCatalog::option('de');
$assert($unsupported['code'] === 'DE' && $unsupported['flag'] === '🌐',
'Historical unsupported codes must remain readable without crashing the resource page.');
echo "Cloud country catalog checks passed.\n";