Test Setup Failed
Push — test ( 546d28...089b88 )
by Jonathan
03:07
created

UtilsTest::testIsSequential()   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
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
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
    public function sequentialArrayProvider()
82
    {
83
        return array(
84
            'sequential array' => array(
85
                array(1, 2, 3),
86
                true,
87
            ),
88
            'explicit sequential array' => array(
89
                array(0 => 1, 1 => 2, 2 => 3),
90
                true,
91
            ),
92
            'arrays start at 1' => array(
93
                array(1 => 1, 2 => 2, 3 => 3),
94
                false,
95
            ),
96
            'wrong order' => array(
97
                array(0 => 1, 2 => 2, 1 => 3),
98
                false,
99
            ),
100
            'string keys' => array(
101
                array(0 => 1, 1 => 2, 'two' => 3),
102
                false,
103
            ),
104
            'string int keys' => array(
105
                array('0' => 1, '1' => 2, '2' => 3),
106
                true,
107
            ),
108
            'padded string int keys' => array(
109
                array('00' => 1, '01' => 2, '02' => 3),
110
                false,
111
            ),
112
        );
113
    }
114
115
    /**
116
     * @covers \Kint\Utils::isSequential
117
     * @dataProvider sequentialArrayProvider
118
     */
119
    public function testIsSequential($input, $expect)
120
    {
121
        $this->assertSame($expect, Utils::isSequential($input));
122
    }
123
}
124