DiskSpaceMonitorTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. namespace Tests\Unit\Services;
  4. use App\Services\DiskSpaceMonitor;
  5. use Illuminate\Support\Facades\Cache;
  6. use Tests\TestCase;
  7. class DiskSpaceMonitorTest extends TestCase
  8. {
  9. public function testItWarnsWhenFreeSpaceIsBelowThreshold(): void
  10. {
  11. Cache::forget('disk_space_monitor.status');
  12. config([
  13. 'app.disk_space_warning.path' => storage_path(),
  14. 'app.disk_space_warning.threshold_bytes' => PHP_INT_MAX,
  15. 'app.disk_space_warning.cache_seconds' => 300,
  16. ]);
  17. $status = app(DiskSpaceMonitor::class)->status();
  18. $this->assertTrue($status['warning']);
  19. $this->assertNotNull($status['free_bytes']);
  20. }
  21. public function testItDoesNotWarnWhenFreeSpaceIsAboveThreshold(): void
  22. {
  23. Cache::forget('disk_space_monitor.status');
  24. config([
  25. 'app.disk_space_warning.path' => storage_path(),
  26. 'app.disk_space_warning.threshold_bytes' => 1,
  27. 'app.disk_space_warning.cache_seconds' => 300,
  28. ]);
  29. $status = app(DiskSpaceMonitor::class)->status();
  30. $this->assertFalse($status['warning']);
  31. $this->assertNotNull($status['free_bytes']);
  32. }
  33. public function testItFormatsBytes(): void
  34. {
  35. $monitor = new DiskSpaceMonitor();
  36. $this->assertSame('1 ГБ', $monitor->formatBytes(1024 * 1024 * 1024));
  37. $this->assertSame('неизвестно', $monitor->formatBytes(null));
  38. }
  39. }