-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoggerTest.php
More file actions
125 lines (113 loc) · 3.82 KB
/
LoggerTest.php
File metadata and controls
125 lines (113 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
declare(strict_types = 1);
namespace Tests\Innmind\OperatingSystem\CurrentProcess;
use Innmind\OperatingSystem\{
CurrentProcess\Logger,
CurrentProcess\Signals,
CurrentProcess,
};
use Innmind\Server\Control\Server\Process\Pid;
use Innmind\Server\Status\Server\Memory\Bytes;
use Innmind\TimeContinuum\Period;
use Innmind\Immutable\{
Attempt,
SideEffect,
};
use Psr\Log\LoggerInterface;
use PHPUnit\Framework\TestCase;
use Innmind\BlackBox\{
PHPUnit\BlackBox,
Set,
};
class LoggerTest extends TestCase
{
use BlackBox;
public function testInterface()
{
$this->assertInstanceOf(
CurrentProcess::class,
Logger::psr(
$this->createMock(CurrentProcess::class),
$this->createMock(LoggerInterface::class),
),
);
}
public function testId()
{
$this
->forAll(Set\Integers::above(2))
->then(function($id) {
$inner = $this->createMock(CurrentProcess::class);
$inner
->expects($this->once())
->method('id')
->willReturn(Attempt::result($expected = new Pid($id)));
$logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->once())
->method('debug')
->with(
'Current process id is {pid}',
['pid' => $id],
);
$process = Logger::psr($inner, $logger);
$this->assertSame($expected, $process->id()->unwrap());
});
}
public function testAlwaysUseSameSignalInstance()
{
$inner = $this->createMock(CurrentProcess::class);
$logger = $this->createMock(LoggerInterface::class);
$process = Logger::psr($inner, $logger);
$this->assertInstanceOf(Signals\Logger::class, $process->signals());
$this->assertSame($process->signals(), $process->signals());
}
public function testHalt()
{
$period = Period::millisecond(1);
$inner = $this->createMock(CurrentProcess::class);
$inner
->expects($this->once())
->method('halt')
->with($period)
->willReturn(Attempt::result(SideEffect::identity()));
$logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->once())
->method('debug')
->with('Halting current process...');
$process = Logger::psr($inner, $logger);
$this->assertInstanceOf(
SideEffect::class,
$process
->halt($period)
->unwrap(),
);
}
public function testMemory()
{
$this
->forAll(Set\Integers::above(0))
->then(function($memory) {
$inner = $this->createMock(CurrentProcess::class);
$inner
->expects($this->once())
->method('memory')
->willReturn($expected = Bytes::of($memory));
$logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->once())
->method('debug')
->with(
'Current process memory at {memory}',
$this->callback(static function($context) {
return \array_key_exists('memory', $context) &&
\is_string($context['memory']) &&
$context['memory'] !== '';
}),
);
$process = Logger::psr($inner, $logger);
$this->assertSame($expected, $process->memory());
});
}
}