GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 5892ba...e25f6a )
by Baptiste
03:37 queued 29s
created

CacheMemoryTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 97
c 1
b 0
f 1
dl 0
loc 137
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testLoadAverage() 0 16 1
A testProcesses() 0 16 1
A testInterface() 0 8 1
A testCpu() 0 16 1
A testMemory() 0 51 1
A testDisk() 0 16 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Tests\Innmind\Server\Status\Servers\Decorator;
5
6
use Innmind\Server\Status\{
7
    Servers\Decorator\CacheMemory,
8
    Server,
9
    Server\Cpu,
10
    Server\Cpu\Percentage,
11
    Server\Cpu\Cores,
12
    Server\Memory,
13
    Server\Memory\Bytes,
14
    Server\LoadAverage,
15
    Server\Processes,
16
    Server\Disk,
17
};
18
use Innmind\TimeContinuum\{
19
    Clock,
20
    Earth\ElapsedPeriod,
21
    PointInTime,
22
};
23
use PHPUnit\Framework\TestCase;
24
25
class CacheMemoryTest extends TestCase
26
{
27
    public function testInterface()
28
    {
29
        $this->assertInstanceOf(
30
            Server::class,
31
            new CacheMemory(
32
                $this->createMock(Server::class),
33
                $this->createMock(Clock::class),
34
                new ElapsedPeriod(0)
35
            )
36
        );
37
    }
38
39
    public function testCpu()
40
    {
41
        $decorator = new CacheMemory(
42
            $server = $this->createMock(Server::class),
43
            $clock = $this->createMock(Clock::class),
44
            new ElapsedPeriod(42)
45
        );
46
        $server
47
            ->expects($this->once())
48
            ->method('cpu')
49
            ->willReturn($expected = new Cpu(new Percentage(33), new Percentage(33), new Percentage(34), new Cores(1)));
50
        $clock
51
            ->expects($this->never())
52
            ->method('now');
53
54
        $this->assertSame($expected, $decorator->cpu());
55
    }
56
57
    public function testMemory()
58
    {
59
        $decorator = new CacheMemory(
60
            $server = $this->createMock(Server::class),
61
            $clock = $this->createMock(Clock::class),
62
            new ElapsedPeriod(42)
63
        );
64
        $server
65
            ->expects($this->exactly(2))
66
            ->method('memory')
67
            ->will(
68
                $this->onConsecutiveCalls(
69
                    $memory1 = new Memory(new Bytes(42), new Bytes(42), new Bytes(42), new Bytes(42), new Bytes(42), new Bytes(42)),
70
                    $memory2 = new Memory(new Bytes(42), new Bytes(42), new Bytes(42), new Bytes(42), new Bytes(42), new Bytes(42))
71
                )
72
            );
73
        $clock
74
            ->expects($this->at(0))
75
            ->method('now')
76
            ->willReturn(
77
                $first = $this->createMock(PointInTime::class)
78
            );
79
        $clock
80
            ->expects($this->at(1))
81
            ->method('now')
82
            ->willReturn(
83
                $second = $this->createMock(PointInTime::class)
84
            );
85
        $second
86
            ->expects($this->once())
87
            ->method('elapsedSince')
88
            ->with($first)
89
            ->willReturn(new ElapsedPeriod(24));
90
        $clock
91
            ->expects($this->at(2))
92
            ->method('now')
93
            ->willReturn(
94
                $third = $this->createMock(PointInTime::class)
95
            );
96
        $third
97
            ->expects($this->once())
98
            ->method('elapsedSince')
99
            ->with($first)
100
            ->willReturn(new ElapsedPeriod(50));
101
        $clock
102
            ->expects($this->exactly(3))
103
            ->method('now');
104
105
        $this->assertSame($memory1, $decorator->memory()); //put in cache
106
        $this->assertSame($memory1, $decorator->memory()); //load cache
107
        $this->assertSame($memory2, $decorator->memory()); //stale
108
    }
109
110
    public function testProcesses()
111
    {
112
        $decorator = new CacheMemory(
113
            $server = $this->createMock(Server::class),
114
            $clock = $this->createMock(Clock::class),
115
            new ElapsedPeriod(42)
116
        );
117
        $server
118
            ->expects($this->once())
119
            ->method('processes')
120
            ->willReturn($expected = $this->createMock(Processes::class));
121
        $clock
122
            ->expects($this->never())
123
            ->method('now');
124
125
        $this->assertSame($expected, $decorator->processes());
126
    }
127
128
    public function testLoadAverage()
129
    {
130
        $decorator = new CacheMemory(
131
            $server = $this->createMock(Server::class),
132
            $clock = $this->createMock(Clock::class),
133
            new ElapsedPeriod(42)
134
        );
135
        $server
136
            ->expects($this->once())
137
            ->method('loadAverage')
138
            ->willReturn($expected = new LoadAverage(1, 5, 15));
139
        $clock
140
            ->expects($this->never())
141
            ->method('now');
142
143
        $this->assertSame($expected, $decorator->loadAverage());
144
    }
145
146
    public function testDisk()
147
    {
148
        $decorator = new CacheMemory(
149
            $server = $this->createMock(Server::class),
150
            $clock = $this->createMock(Clock::class),
151
            new ElapsedPeriod(42)
152
        );
153
        $server
154
            ->expects($this->once())
155
            ->method('disk')
156
            ->willReturn($expected = $this->createMock(Disk::class));
157
        $clock
158
            ->expects($this->never())
159
            ->method('now');
160
161
        $this->assertSame($expected, $decorator->disk());
162
    }
163
}
164