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;
}
});
+3 -3
View File
@@ -76,7 +76,7 @@ trait minio_t
public function getEndpoint(): string
{
global $MINIO;
return $MINIO['endpoint'];
return is_array($MINIO ?? null) ? (string)($MINIO['endpoint'] ?? '') : '';
}
/**
@@ -86,7 +86,7 @@ trait minio_t
public function getAccessKey(): string
{
global $MINIO;
return $MINIO['access_key'];
return is_array($MINIO ?? null) ? (string)($MINIO['access_key'] ?? '') : '';
}
/**
@@ -96,7 +96,7 @@ trait minio_t
public function getSecretKey(): string
{
global $MINIO;
return $MINIO['secret_key'];
return is_array($MINIO ?? null) ? (string)($MINIO['secret_key'] ?? '') : '';
}
/**