44 lines
1.6 KiB
PHP
44 lines
1.6 KiB
PHP
<?php
|
|||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
require_once __DIR__ . '/../bin/healthcheck.php';
|
||
|
|
|
||
|
|
function deployment_test_assert(bool $condition, string $message): void
|
||
|
|
{
|
||
|
|
if (!$condition) {
|
||
|
|
throw new RuntimeException($message);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$checks = 0;
|
||
|
|
|
||
|
|
$extensions = deployment_check_extensions(
|
||
|
|
['present_ext', 'missing_ext'],
|
||
|
|
static fn(string $extension): bool => $extension === 'present_ext',
|
||
|
|
);
|
||
|
|
deployment_test_assert($extensions === ['present_ext' => true, 'missing_ext' => false], 'Extension checks must preserve names and availability.');
|
||
|
|
$checks++;
|
||
|
|
|
||
|
|
$environment = deployment_check_environment(
|
||
|
|
['DB_HOST', 'DB_PASSWORD', 'EMPTY_VALUE'],
|
||
|
|
static fn(string $name): ?string => ['DB_HOST' => 'localhost', 'DB_PASSWORD' => 'secret', 'EMPTY_VALUE' => ' '][$name] ?? null,
|
||
|
|
);
|
||
|
|
deployment_test_assert($environment === ['DB_HOST' => true, 'DB_PASSWORD' => true, 'EMPTY_VALUE' => false], 'Environment checks must only report presence, never values.');
|
||
|
|
$checks++;
|
||
|
|
|
||
|
|
$directories = deployment_check_directories(
|
||
|
|
['/srv/jobcard/runtime', '/srv/jobcard/uploads'],
|
||
|
|
static fn(string $directory): bool => $directory === '/srv/jobcard/runtime',
|
||
|
|
);
|
||
|
|
deployment_test_assert($directories === ['/srv/jobcard/runtime' => true, '/srv/jobcard/uploads' => false], 'Directory checks must report writability without changing directories.');
|
||
|
|
$checks++;
|
||
|
|
|
||
|
|
$report = deployment_format_check_report([
|
||
|
|
'DB_PASSWORD' => true,
|
||
|
|
'DB_HOST' => false,
|
||
|
|
]);
|
||
|
|
deployment_test_assert($report === ['DB_PASSWORD' => 'OK', 'DB_HOST' => 'FAIL'], 'Reports must contain statuses only.');
|
||
|
|
$checks++;
|
||
|
|
|
||
|
|
printf("Deployment checks tests: %d passed\n", $checks);
|