1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Tests\Innmind\Server\Status\Server\Disk; |
5
|
|
|
|
6
|
|
|
use Innmind\Server\Status\{ |
7
|
|
|
Server\Disk\UnixDisk, |
8
|
|
|
Server\Disk, |
9
|
|
|
Server\Disk\Volume, |
10
|
|
|
Server\Disk\Volume\MountPoint, |
11
|
|
|
Exception\DiskUsageNotAccessible, |
12
|
|
|
}; |
13
|
|
|
use Innmind\Immutable\Map; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
class UnixDiskTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
public function testInterface() |
19
|
|
|
{ |
20
|
|
|
$this->assertInstanceOf(Disk::class, new UnixDisk); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testVolumes() |
24
|
|
|
{ |
25
|
|
|
if (!in_array(PHP_OS, ['Darwin', 'Linux'])) { |
26
|
|
|
return; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$volumes = (new UnixDisk)->volumes(); |
30
|
|
|
|
31
|
|
|
$this->assertInstanceOf(Map::class, $volumes); |
32
|
|
|
$this->assertSame('string', (string) $volumes->keyType()); |
33
|
|
|
$this->assertSame(Volume::class, (string) $volumes->valueType()); |
34
|
|
|
$this->assertTrue($volumes->size() > 0); |
35
|
|
|
$this->assertTrue($volumes->contains('/')); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testGet() |
39
|
|
|
{ |
40
|
|
|
if (!in_array(PHP_OS, ['Darwin', 'Linux'])) { |
41
|
|
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$volume = (new UnixDisk)->get(new MountPoint('/')); |
45
|
|
|
|
46
|
|
|
$this->assertInstanceOf(Volume::class, $volume); |
47
|
|
|
$this->assertSame('/', $volume->mountPoint()->toString()); |
48
|
|
|
$this->assertTrue($volume->size()->toInt() > 0); |
49
|
|
|
$this->assertTrue($volume->available()->toInt() > 0); |
50
|
|
|
$this->assertTrue($volume->used()->toInt() > 0); |
51
|
|
|
$this->assertTrue($volume->usage()->toFloat() > 0); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testThrowWhenCommandFails() |
55
|
|
|
{ |
56
|
|
|
if (in_array(PHP_OS, ['Darwin', 'Linux'])) { |
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->expectException(DiskUsageNotAccessible::class); |
61
|
|
|
|
62
|
|
|
(new UnixDisk)->volumes(); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|