| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- declare(strict_types=1);
- namespace Tests\Unit\Services;
- use App\Services\DiskSpaceMonitor;
- use Illuminate\Support\Facades\Cache;
- use Tests\TestCase;
- class DiskSpaceMonitorTest extends TestCase
- {
- public function testItWarnsWhenFreeSpaceIsBelowThreshold(): void
- {
- Cache::forget('disk_space_monitor.status');
- config([
- 'app.disk_space_warning.path' => storage_path(),
- 'app.disk_space_warning.threshold_bytes' => PHP_INT_MAX,
- 'app.disk_space_warning.cache_seconds' => 300,
- ]);
- $status = app(DiskSpaceMonitor::class)->status();
- $this->assertTrue($status['warning']);
- $this->assertNotNull($status['free_bytes']);
- }
- public function testItDoesNotWarnWhenFreeSpaceIsAboveThreshold(): void
- {
- Cache::forget('disk_space_monitor.status');
- config([
- 'app.disk_space_warning.path' => storage_path(),
- 'app.disk_space_warning.threshold_bytes' => 1,
- 'app.disk_space_warning.cache_seconds' => 300,
- ]);
- $status = app(DiskSpaceMonitor::class)->status();
- $this->assertFalse($status['warning']);
- $this->assertNotNull($status['free_bytes']);
- }
- public function testItFormatsBytes(): void
- {
- $monitor = new DiskSpaceMonitor();
- $this->assertSame('1 ГБ', $monitor->formatBytes(1024 * 1024 * 1024));
- $this->assertSame('неизвестно', $monitor->formatBytes(null));
- }
- }
|