shouldReceive('exists')->with($configPath)->andReturn(true); $mock->shouldReceive('exists')->with($installerEntryPoint)->andReturn(false); $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)); });