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

CacheLoadAverageTest::testLoadAverage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 42
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 51
rs 9.248

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\CacheLoadAverage,
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 CacheLoadAverageTest extends TestCase
26
{
27
    public function testInterface()
28
    {
29
        $this->assertInstanceOf(
30
            Server::class,
31
            new CacheLoadAverage(
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 CacheLoadAverage(
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 CacheLoadAverage(
60
            $server = $this->createMock(Server::class),
61
            $clock = $this->createMock(Clock::class),
62
            new ElapsedPeriod(42)
63
        );
64
        $server
65
            ->expects($this->once())
66
            ->method('memory')
67
            ->willReturn($expected = new Memory(
68
                new Bytes(42),
69
                new Bytes(42),
70
                new Bytes(42),
71
                new Bytes(42),
72
                new Bytes(42),
73
                new Bytes(42)
74
            ));
75
        $clock
76
            ->expects($this->never())
77
            ->method('now');
78
79
        $this->assertSame($expected, $decorator->memory());
80
    }
81
82
    public function testProcesses()
83
    {
84
        $decorator = new CacheLoadAverage(
85
            $server = $this->createMock(Server::class),
86
            $clock = $this->createMock(Clock::class),
87
            new ElapsedPeriod(42)
88
        );
89
        $server
90
            ->expects($this->once())
91
            ->method('processes')
92
            ->willReturn($expected = $this->createMock(Processes::class));
93
        $clock
94
            ->expects($this->never())
95
            ->method('now');
96
97
        $this->assertSame($expected, $decorator->processes());
98
    }
99
100
    public function testLoadAverage()
101
    {
102
        $decorator = new CacheLoadAverage(
103
            $server = $this->createMock(Server::class),
104
            $clock = $this->createMock(Clock::class),
105
            new ElapsedPeriod(42)
106
        );
107
        $server
108
            ->expects($this->exactly(2))
109
            ->method('loadAverage')
110
            ->will(
111
                $this->onConsecutiveCalls(
112
                    $load1 = new LoadAverage(1, 5, 15),
113
                    $load2 = new LoadAverage(1, 5, 15)
114
                )
115
            );
116
        $clock
117
            ->expects($this->at(0))
118
            ->method('now')
119
            ->willReturn(
120
                $first = $this->createMock(PointInTime::class)
121
            );
122
        $clock
123
            ->expects($this->at(1))
124
            ->method('now')
125
            ->willReturn(
126
                $second = $this->createMock(PointInTime::class)
127
            );
128
        $second
129
            ->expects($this->once())
130
            ->method('elapsedSince')
131
            ->with($first)
132
            ->willReturn(new ElapsedPeriod(24));
133
        $clock
134
            ->expects($this->at(2))
135
            ->method('now')
136
            ->willReturn(
137
                $third = $this->createMock(PointInTime::class)
138
            );
139
        $third
140
            ->expects($this->once())
141
            ->method('elapsedSince')
142
            ->with($first)
143
            ->willReturn(new ElapsedPeriod(50));
144
        $clock
145
            ->expects($this->exactly(3))
146
            ->method('now');
147
148
        $this->assertSame($load1, $decorator->loadAverage()); //put in cache
149
        $this->assertSame($load1, $decorator->loadAverage()); //load cache
150
        $this->assertSame($load2, $decorator->loadAverage()); //stale
151
    }
152
153
    public function testDisk()
154
    {
155
        $decorator = new CacheLoadAverage(
156
            $server = $this->createMock(Server::class),
157
            $clock = $this->createMock(Clock::class),
158
            new ElapsedPeriod(42)
159
        );
160
        $server
161
            ->expects($this->once())
162
            ->method('disk')
163
            ->willReturn($expected = $this->createMock(Disk::class));
164
        $clock
165
            ->expects($this->never())
166
            ->method('now');
167
168
        $this->assertSame($expected, $decorator->disk());
169
    }
170
}
171