Files
FOSSBilling/tests/Unit/LoadCheckInstallerTest.php
T
Adam Daley 981545c969 Remove installer from production debug deployments
Remove the debug carve-outs so production installs always delete the
install directory, including debug-enabled instances.

Ported from main commit 8484943ad (#4322).
2026-09-19 10:39:59 +01:00

53 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
/**
* Stubs the global $filesystem used by checkInstaller() so the test never touches real
* disk.
*/
function runCheckInstallerWithStubbedFilesystem(bool $expectRemoval): void
{
$configPath = PATH_CONFIG;
$installDir = Path::normalize('install');
$mock = Mockery::mock(Filesystem::class);
$mock->shouldReceive('exists')->with($configPath)->andReturn(true);
$mock->shouldReceive('exists')->with($installDir)->andReturn(true);
if ($expectRemoval) {
$mock->shouldReceive('remove')->once()->with('install');
} else {
$mock->shouldNotReceive('remove');
}
$previousFilesystem = $GLOBALS['filesystem'] ?? null;
$GLOBALS['filesystem'] = $mock;
try {
checkInstaller();
} finally {
$GLOBALS['filesystem'] = $previousFilesystem;
}
}
test('checkInstaller deletes the install directory when APP_ENV is unset', function (): void {
withAppEnv(null, fn () => runCheckInstallerWithStubbedFilesystem(expectRemoval: true));
});
test('checkInstaller deletes the install directory when APP_ENV holds an unrecognized value', function (): void {
withAppEnv('staging', fn () => runCheckInstallerWithStubbedFilesystem(expectRemoval: true));
});
test('checkInstaller does not delete the install directory when APP_ENV is dev or test', function (): void {
withAppEnv('dev', fn () => runCheckInstallerWithStubbedFilesystem(expectRemoval: false));
withAppEnv('test', fn () => runCheckInstallerWithStubbedFilesystem(expectRemoval: false));
});
test('checkInstaller deletes the install directory when APP_ENV is explicitly prod', function (): void {
withAppEnv('prod', fn () => runCheckInstallerWithStubbedFilesystem(expectRemoval: true));
});