mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-04 02:57:11 +09:00
52 lines
1.9 KiB
PHP
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));
|
|
});
|