|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Tests\Innmind\Server\Status\Server\Processes; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\Server\Status\{ |
|
7
|
|
|
Server\Processes\UnixProcesses, |
|
8
|
|
|
Server\Processes, |
|
9
|
|
|
Server\Process, |
|
10
|
|
|
Server\Process\Pid, |
|
11
|
|
|
Exception\InformationNotAccessible, |
|
12
|
|
|
}; |
|
13
|
|
|
use Innmind\TimeContinuum\Earth\Clock; |
|
14
|
|
|
use Innmind\Immutable\Map; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
class UnixProcessesTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
public function testInterface() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->assertInstanceOf(Processes::class, new UnixProcesses(new Clock)); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testAll() |
|
25
|
|
|
{ |
|
26
|
|
|
if (!in_array(PHP_OS, ['Darwin', 'Linux'])) { |
|
27
|
|
|
return; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
$all = (new UnixProcesses(new Clock))->all(); |
|
31
|
|
|
|
|
32
|
|
|
$this->assertInstanceOf(Map::class, $all); |
|
33
|
|
|
$this->assertSame('int', (string) $all->keyType()); |
|
34
|
|
|
$this->assertSame(Process::class, (string) $all->valueType()); |
|
35
|
|
|
$this->assertTrue($all->size() > 0); |
|
36
|
|
|
$this->assertSame('root', $all->get(1)->user()->toString()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGet() |
|
40
|
|
|
{ |
|
41
|
|
|
if (!in_array(PHP_OS, ['Darwin', 'Linux'])) { |
|
42
|
|
|
return; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$process = (new UnixProcesses(new Clock))->get(new Pid(1)); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertInstanceOf(Process::class, $process); |
|
48
|
|
|
$this->assertSame('root', $process->user()->toString()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testThrowWhenProcessFails() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->expectException(InformationNotAccessible::class); |
|
54
|
|
|
|
|
55
|
|
|
(new UnixProcesses(new Clock))->get(new Pid(42424)); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|