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.

BytesTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 2
Metric Value
eloc 44
dl 0
loc 91
rs 10
c 6
b 0
f 2
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testThrowWhenUnknownFormat() 0 5 1
A testInterface() 0 6 1
A testThrowWhenNegative() 0 5 1
A invalidStrings() 0 6 1
A testThrowWhenStringTooShort() 0 5 1
A steps() 0 15 1
A testFromString() 0 6 1
A strings() 0 16 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Tests\Innmind\Server\Status\Server\Memory;
5
6
use Innmind\Server\Status\{
7
    Server\Memory\Bytes,
8
    Exception\BytesCannotBeNegative,
9
    Exception\UnknownBytesFormat,
10
};
11
use PHPUnit\Framework\TestCase;
12
13
class BytesTest extends TestCase
14
{
15
    /**
16
     * @dataProvider steps
17
     */
18
    public function testInterface($value, $expected)
19
    {
20
        $bytes = new Bytes($value);
21
22
        $this->assertSame($value, $bytes->toInt());
23
        $this->assertSame($expected, $bytes->toString());
24
    }
25
26
    public function testThrowWhenNegative()
27
    {
28
        $this->expectException(BytesCannotBeNegative::class);
29
30
        new Bytes(-1);
31
    }
32
33
    /**
34
     * @dataProvider strings
35
     */
36
    public function testFromString($string, $expected)
37
    {
38
        $bytes = Bytes::of($string);
39
40
        $this->assertInstanceOf(Bytes::class, $bytes);
41
        $this->assertSame($expected, $bytes->toString());
42
    }
43
44
    public function testThrowWhenUnknownFormat()
45
    {
46
        $this->expectException(UnknownBytesFormat::class);
47
48
        Bytes::of('42Br');
49
    }
50
51
    /**
52
     * @dataProvider invalidStrings
53
     */
54
    public function testThrowWhenStringTooShort($string)
55
    {
56
        $this->expectException(UnknownBytesFormat::class);
57
58
        Bytes::of($string);
59
    }
60
61
    public function steps(): array
62
    {
63
        return [
64
            [512, '512B'],
65
            [1023, '1023B'],
66
            [1024, '1KB'],
67
            [(1024 ** 2)-1, '1023.999KB'],
68
            [1024 ** 2, '1MB'],
69
            [(1024 ** 3)-1, '1024MB'],
70
            [1024 ** 3, '1GB'],
71
            [(1024 ** 4)-1, '1024GB'],
72
            [1024 ** 4, '1TB'],
73
            [(1024 ** 5)-1, '1024TB'],
74
            [1024 ** 5, '1PB'],
75
            [(1024 ** 6)-1, '1024PB'],
76
        ];
77
    }
78
79
    public function strings(): array
80
    {
81
        return [
82
            ['42', '42B'],
83
            ['42B', '42B'],
84
            ['42Bi', '42B'],
85
            ['42K', '42KB'],
86
            ['42Ki', '42KB'],
87
            ['42M', '42MB'],
88
            ['42Mi', '42MB'],
89
            ['42G', '42GB'],
90
            ['42Gi', '42GB'],
91
            ['42T', '42TB'],
92
            ['42Ti', '42TB'],
93
            ['42P', '42PB'],
94
            ['42Pi', '42PB'],
95
        ];
96
    }
97
98
    public function invalidStrings(): array
99
    {
100
        return [
101
            [''],
102
            ['B'],
103
            ['Bi'],
104
        ];
105
    }
106
}
107