Files
FOSSBilling/tests/Unit/LoadCheckInstallerTest.php
Adam Daley 8484943ad6 Remove installer from production debug deployments (#4322)
🔒 Remove installer from production debug deployments
2026-09-15 21:34:27 +01:00

52 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
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;
ini_set('error_log', '/dev/null');
try {
checkInstaller();
} finally {
$GLOBALS['filesystem'] = $previousFilesystem;
// Keep the suite-wide test logging policy after exercising the production cleanup path.
ini_set('error_log', '/dev/null');
}
}
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));
});