/var/www/hkosl.com/imusiccircle/webadmin/libraies/php-console/php-console/tests/Test/Dumper.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php

namespace PhpConsole\Test;

class 
Dumper extends Test {

    
/** @var  \PhpConsole\Dumper */
    
protected $dumper;

    protected function 
setUp() {
        
parent::setUp();
        
$this->dumper = new \PhpConsole\Dumper();
    }

    public function 
testScalarItemSizeLimit() {
        
$this->dumper->itemSizeLimit 5;
        
$dumpedString $this->dumper->dump(str_repeat('x'$this->dumper->itemSizeLimit 2));
        
$this->assertEquals($this->dumper->itemSizeLimitstrlen($dumpedString));
        
$this->assertStringEndsWith('...'$dumpedString);
    }

    public function 
testScalarDumpSizeLimit() {
        
$this->dumper->dumpSizeLimit 5;
        
$dumpedString $this->dumper->dump(str_repeat('x'$this->dumper->dumpSizeLimit 2));
        
$this->assertEquals($this->dumper->dumpSizeLimitstrlen($dumpedString));
        
$this->assertStringEndsWith('...'$dumpedString);
    }

    public function 
testItemsCountLimit() {
        
$this->dumper->itemsCountLimit 3;
        
$source = array(12345);
        
$expected = array(123'...' => '(displayed 3 of 5)');
        
$this->assertEquals($expected$this->dumper->dump($source));
        
$this->assertEquals(array(array($expected)), $this->dumper->dump(array(array($source))));
    }

    public function 
testLevelLimit() {
        
$this->dumper->levelLimit 2;
        
$source = array(
            
0,
            
=> array(=> array(=> array(=> array()))),
            array(
2, array(3, array(4, array()))),
        );
        
$expected = array(
            
=> 0,
            
=>
            array(
                
=> '(array)',
            ),
            
=>
            array(
                
=> 2,
                
=> '(array)',
            ));
        
$this->assertEquals($expected$this->dumper->dump($source));
    }

    public function 
testMixedDataLimits() {
        
$this->dumper->levelLimit 3;
        
$this->dumper->itemsCountLimit 3;
        
$this->dumper->itemSizeLimit 5;

        
$source = new \stdClass();
        
$source->null null;
        
$source->scalar 123456;
        
$source->obj = new \stdClass();
        
$source->obj->sca 345678;
        
$source->obj->arr = array(array());
        
$source->array = array(
            
'scalar' => 234567,
            
'obj' => new \stdClass(),
            
=> array(33),
            
4,
            
5
        
);

        
$expected = array(
            
':stdClass' => array(
                
'null' => null,
                
'scalar' => '12...',
                
'obj:stdClass' => array(
                    
'sca' => '34...',
                    
'arr' => array(
                        
=> '(array)',
                    ),
                ),
                
'...' => '(displayed 3 of 4)',
            ));

        
$this->assertEquals($expected$this->dumper->dump($source));
    }

    public function 
testDumpBinaryData() {
        
$binaryData sha1(123true);
        
$this->assertEquals($binaryData$this->dumper->dump($binaryData));
        
$this->dumper->itemSizeLimit 10;
        
$this->assertEquals(substr($binaryData07) . '...'$this->dumper->dump($binaryData));
    }

    public function 
testObjectProtectedPrivateProperties() {
        
$this->assertEquals(array(
            
':PhpConsole\Test\DumperDraftClass' => array(
                
'public' => 321,
                
'protected' => 123,
                
'private' => 234,
            )), 
$this->dumper->dump(new DumperDraftClass()));
    }

    public function 
testObjectsRecursion() {
        
$object = new \stdClass();
        
$object->obj $object;
        
$this->assertEquals(array(
            
':stdClass' => array(
                
'obj:stdClass' => '*RECURSION*'
            
)), $this->dumper->dump($object));
    }

    public function 
testFunctionDump() {
        
$function = function () {
        };
        
$this->assertEquals('(callback function)'$this->dumper->dump($function));
        
$this->assertEquals(array('(callback function)'), $this->dumper->dump(array($function)));
    }

    public function 
testCallbacksDump() {
        
$object = new DumperDraftClass();
        
$source = array(
            array(
$object'publicMethod'),
            array(
'PhpConsole\Test\DumperDraftClass''staticMethod')
        );
        
$this->assertEquals(array(
            
=> '(callback PhpConsole\Test\DumperDraftClass::publicMethod)',
            
=> '(callback PhpConsole\Test\DumperDraftClass::staticMethod)'
        
), $this->dumper->dump($source));
    }

    public function 
testDumpSizeLimit() {
        
$this->dumper->dumpSizeLimit 50;
        
$source = array(
            
1,
            
=> array(
                
21,
                
22
            
),
            
=> array(33),
            
4,
            
5
        
);
        
$expected = array(
            
=> 1,
            
=>
            array(
                
=> 21,
                
'...' => '(displayed 1 of 2)',
            ),
            
=> array(
                
=> 33,
            ),
            
=> 4,
            
=> 5,
        );
        
$this->assertEquals($expected$this->dumper->dump($source));
    }
}

class 
DumperDraftClass {

    public 
$public 321;
    protected 
$protected 123;
    private 
$private 234;

    public function 
publicMethod() {
    }

    public static function 
staticMethod() {
    }
}