35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require __DIR__.'/../public/perspektivwerk/booking/backend.php';
|
|
|
|
function expectSame(string $expected, string $actual, string $message): void
|
|
{
|
|
if ($expected !== $actual) {
|
|
throw new RuntimeException($message."\nExpected: $expected\nActual: $actual");
|
|
}
|
|
}
|
|
|
|
$configFile = tempnam(sys_get_temp_dir(), 'sufw-booking-config-');
|
|
if ($configFile === false) throw new RuntimeException('Temporary configuration file could not be created.');
|
|
|
|
try {
|
|
file_put_contents($configFile, "<?php\nreturn ['database_url' => 'mysql://fallback:secret@database:3306/booking'];\n");
|
|
|
|
expectSame(
|
|
'mysql://fallback:secret@database:3306/booking',
|
|
bookingDatabaseUrl('', $configFile),
|
|
'The configuration file must be used when DATABASE_URL is empty.'
|
|
);
|
|
expectSame(
|
|
'mysql://environment:secret@database:3306/booking',
|
|
bookingDatabaseUrl('mysql://environment:secret@database:3306/booking', $configFile),
|
|
'DATABASE_URL must take precedence over the configuration file.'
|
|
);
|
|
} finally {
|
|
unlink($configFile);
|
|
}
|
|
|
|
echo "booking backend configuration tests passed\n";
|