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::testMemory()   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\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