Test Setup Failed
Push — test ( ba2df3...546d28 )
by Jonathan
05:09 queued 01:53
created

UtilsTest::testGetHumanReadableBytes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Kint\Test;
4
5
use Kint\Utils;
6
use PHPUnit_Framework_TestCase;
7
8
class UtilsTest extends PHPUnit_Framework_TestCase
9
{
10
    public function humanReadableBytesProvider()
11
    {
12
        return array(
13
            '1 byte' => array(
14
                1,
15
                array(
16
                    'value' => 1.0,
17
                    'unit' => 'B',
18
                ),
19
            ),
20
            '1023 bytes' => array(
21
                1023,
22
                array(
23
                    'value' => 1023.0,
24
                    'unit' => 'B',
25
                ),
26
            ),
27
            '1024 bytes' => array(
28
                1024,
29
                array(
30
                    'value' => 1.0,
31
                    'unit' => 'KB',
32
                ),
33
            ),
34
            '1 meg' => array(
35
                pow(2, 20),
36
                array(
37
                    'value' => 1.0,
38
                    'unit' => 'MB',
39
                ),
40
            ),
41
            '1 gig' => array(
42
                pow(2, 30),
43
                array(
44
                    'value' => 1.0,
45
                    'unit' => 'GB',
46
                ),
47
            ),
48
            '1 tig' => array(
49
                pow(2, 40),
50
                array(
51
                    'value' => 1.0,
52
                    'unit' => 'TB',
53
                ),
54
            ),
55
            '>1 tig' => array(
56
                pow(2, 50),
57
                array(
58
                    'value' => 1024.0,
59
                    'unit' => 'TB',
60
                ),
61
            ),
62
            'halfway' => array(
63
                15000,
64
                array(
65
                    'value' => 15000 / 1024,
66
                    'unit' => 'KB',
67
                ),
68
            ),
69
        );
70
    }
71
72
    /**
73
     * @covers \Kint\Utils::getHumanReadableBytes
74
     * @dataProvider humanReadableBytesProvider
75
     */
76
    public function testGetHumanReadableBytes($input, $expect)
77
    {
78
        $this->assertSame($expect, Utils::getHumanReadableBytes($input));
79
    }
80
}
81