mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-04 19:17:46 +09:00
Remove the debug carve-outs so production installs always delete the
install directory, including debug-enabled instances.
Ported from main commit 8484943ad (#4322).
53 lines
1.8 KiB
PHP
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));
|
|
});
|