Fix MinIO local test storage fallback

This commit is contained in:
Jeppe B
2026-06-10 18:22:53 +02:00
parent cb34b030c8
commit ce999afbb3
2 changed files with 41 additions and 3 deletions
@@ -0,0 +1,38 @@
<?php
use classes\pdf_store;
it('falls back to local test storage when MinIO config values are empty', function (): void {
global $MINIO;
$previousRunApiTests = getenv('RUN_API_TESTS');
$previousMinio = $MINIO ?? null;
putenv('RUN_API_TESTS=1');
$MINIO = [
'endpoint' => null,
'access_key' => null,
'secret_key' => null,
];
try {
$file = 'minio-local-test-' . bin2hex(random_bytes(4)) . '.pdf';
$store = new pdf_store();
expect($store->createObject($file, 'local-pdf-content'))->toBeTrue();
$path = $store->download($file);
expect(is_file($path))->toBeTrue()
->and(file_get_contents($path))->toBe('local-pdf-content');
} finally {
if (isset($path) && is_file($path)) {
unlink($path);
}
if ($previousRunApiTests === false) {
putenv('RUN_API_TESTS');
} else {
putenv('RUN_API_TESTS=' . $previousRunApiTests);
}
$MINIO = $previousMinio;
}
});