Files
coruna-lab/tests/TestCase.php
T
hashbro 51336e346a Keep Tokenview and Telegram running when log files are not writable.
Daily logs created by root cron were blocking www from appending, which aborted webhook ingest and bot pushes. File channels now use 0664 plus exception-safe stacks, and writes go through SafeLog.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-15 11:40:44 +08:00

44 lines
1.1 KiB
PHP

<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Log;
abstract class TestCase extends BaseTestCase
{
/**
* Point a Laravel log channel at a directory the process cannot write.
* Used to prove SafeLog / ignore_exceptions do not abort business work.
*/
protected function forceLogChannelUnwritable(string $channel): string
{
$dir = sys_get_temp_dir().'/coruna-unwritable-log-'.uniqid('', true);
mkdir($dir, 0700);
chmod($dir, 0500);
config([
"logging.channels.{$channel}" => [
'driver' => 'single',
'path' => $dir.'/blocked.log',
'level' => 'debug',
],
]);
Log::forgetChannel($channel);
return $dir;
}
protected function restoreWritableLogDir(string $dir): void
{
if ($dir === '' || ! is_dir($dir)) {
return;
}
@chmod($dir, 0700);
foreach (glob($dir.'/*') ?: [] as $file) {
@unlink($file);
}
@rmdir($dir);
}
}