1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kint\Test; |
4
|
|
|
|
5
|
|
|
use Kint\Kint; |
6
|
|
|
use Kint\Test\Fixtures\Php56TestClass; |
7
|
|
|
use Kint\Test\Fixtures\TestClass; |
8
|
|
|
use ReflectionClass; |
9
|
|
|
use ReflectionMethod; |
10
|
|
|
use ReflectionProperty; |
11
|
|
|
|
12
|
|
|
class KintTest extends KintTestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @covers \Kint\Kint::settings |
16
|
|
|
*/ |
17
|
|
|
public function testSettings() |
18
|
|
|
{ |
19
|
|
|
$r = new ReflectionClass('Kint'); |
|
|
|
|
20
|
|
|
|
21
|
|
|
$props = $r->getProperties(ReflectionProperty::IS_STATIC); |
22
|
|
|
$props_array = array(); |
|
|
|
|
23
|
|
|
foreach ($props as $prop) { |
24
|
|
|
if ($prop->isPublic() && $prop->isStatic()) { |
25
|
|
|
$props_array[$prop->getName()] = $prop->getValue(); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$props = $r->getStaticProperties(); |
30
|
|
|
|
31
|
|
|
$this->assertEquals($props_array, $stash = Kint::settings()); |
|
|
|
|
32
|
|
|
|
33
|
|
|
$props_array['enabled_mode'] = Kint::$enabled_mode = false; |
|
|
|
|
34
|
|
|
$props_array['file_link_format'] = Kint::$file_link_format = 'linky'; |
|
|
|
|
35
|
|
|
$props_array['app_root_dirs'] = Kint::$app_root_dirs = array('/' => '<fsroot>'); |
|
|
|
|
36
|
|
|
$props_array['max_depth'] = Kint::$max_depth = 0; |
|
|
|
|
37
|
|
|
$props_array['expanded'] = Kint::$expanded = true; |
|
|
|
|
38
|
|
|
$props_array['cli_detection'] = Kint::$cli_detection = false; |
|
|
|
|
39
|
|
|
|
40
|
|
|
$this->assertNotEquals($props, $r->getStaticProperties()); |
41
|
|
|
$this->assertEquals($props_array, Kint::settings($stash)); |
|
|
|
|
42
|
|
|
$this->assertEquals($props, $r->getStaticProperties()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function pathProvider() |
46
|
|
|
{ |
47
|
|
|
return array( |
48
|
|
|
'standard file' => array( |
49
|
|
|
'path' => __FILE__, |
50
|
|
|
'expect' => '<tests>/KintTest.php', |
51
|
|
|
), |
52
|
|
|
'standard dir' => array( |
53
|
|
|
'path' => __DIR__, |
54
|
|
|
'expect' => '<tests>', |
55
|
|
|
), |
56
|
|
|
'parent dir' => array( |
57
|
|
|
'path' => KINT_DIR, |
58
|
|
|
'expect' => '<kint>', |
59
|
|
|
), |
60
|
|
|
'sub file' => array( |
61
|
|
|
'path' => KINT_DIR.'/src//test', |
62
|
|
|
'expect' => '<kint>/src/test', |
63
|
|
|
), |
64
|
|
|
'common path' => array( |
65
|
|
|
'path' => dirname(KINT_DIR).'/test/', |
66
|
|
|
'expect' => '.../test', |
67
|
|
|
), |
68
|
|
|
'root path' => array( |
69
|
|
|
'path' => '/', |
70
|
|
|
'expect' => '/', |
71
|
|
|
), |
72
|
|
|
'no common path' => array( |
73
|
|
|
'path' => '/asdfasdf/test/', |
74
|
|
|
'expect' => '/asdfasdf/test', |
75
|
|
|
), |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @dataProvider pathProvider |
81
|
|
|
* @covers \Kint\Kint::shortenPath |
82
|
|
|
*/ |
83
|
|
|
public function testShortenPath($path, $expect) |
84
|
|
|
{ |
85
|
|
|
Kint::$app_root_dirs = array( |
86
|
|
|
KINT_DIR => '<kint>', |
87
|
|
|
KINT_DIR.'/test' => '<test>', |
88
|
|
|
'' => '<Nothing!>', |
89
|
|
|
__DIR__ => '<tests>', |
90
|
|
|
KINT_DIR.'/tes' => '<tes>', |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$this->assertEquals($expect, Kint::shortenPath($path)); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @covers \Kint\Kint::getIdeLink |
98
|
|
|
*/ |
99
|
|
|
public function testGetIdeLink() |
100
|
|
|
{ |
101
|
|
|
Kint::$file_link_format = '<a href="%f:%l">%f:%l</a>'; |
102
|
|
|
|
103
|
|
|
$file = uniqid('', true); |
104
|
|
|
$line = uniqid('', true); |
105
|
|
|
|
106
|
|
|
$this->assertEquals('<a href="'.$file.':'.$line.'">'.$file.':'.$line.'</a>', Kint::getIdeLink($file, $line)); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getCalleeInfoProvider() |
110
|
|
|
{ |
111
|
|
|
$basetrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
112
|
|
|
$dumpframe = array( |
113
|
|
|
'class' => 'Kint', |
114
|
|
|
'function' => 'dump', |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
$data['empty trace'] = array( |
|
|
|
|
118
|
|
|
'trace' => array( |
119
|
|
|
), |
120
|
|
|
'param_count' => 1234, |
121
|
|
|
'expect' => array( |
122
|
|
|
null, |
123
|
|
|
array(), |
124
|
|
|
null, |
125
|
|
|
null, |
126
|
|
|
array(), |
127
|
|
|
), |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
$data['full trace'] = array( |
131
|
|
|
'trace' => array_merge(array($dumpframe), $basetrace), |
132
|
|
|
'param_count' => 1234, |
133
|
|
|
'expect' => array( |
134
|
|
|
null, |
135
|
|
|
array(), |
136
|
|
|
$dumpframe, |
137
|
|
|
array( |
138
|
|
|
'function' => __FUNCTION__, |
139
|
|
|
'class' => __CLASS__, |
140
|
|
|
'type' => '->', |
141
|
|
|
), |
142
|
|
|
), |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
$data['trace with params'] = array( |
146
|
|
|
'trace' => array_merge( |
147
|
|
|
array( |
148
|
|
|
$dumpframe + array( |
149
|
|
|
'file' => TestClass::DUMP_FILE, |
150
|
|
|
'line' => TestClass::DUMP_LINE, |
151
|
|
|
), |
152
|
|
|
), |
153
|
|
|
$basetrace |
154
|
|
|
), |
155
|
|
|
'param_count' => 3, |
156
|
|
|
'expect' => array( |
157
|
|
|
array( |
158
|
|
|
array('name' => '$x', 'path' => '$x', 'expression' => false), |
159
|
|
|
array('name' => '$y', 'path' => '$y', 'expression' => false), |
160
|
|
|
array('name' => '$z', 'path' => '$z', 'expression' => false), |
161
|
|
|
), |
162
|
|
|
array(), |
163
|
|
|
$dumpframe + array( |
164
|
|
|
'file' => TestClass::DUMP_FILE, |
165
|
|
|
'line' => TestClass::DUMP_LINE, |
166
|
|
|
), |
167
|
|
|
), |
168
|
|
|
); |
169
|
|
|
|
170
|
|
|
$data['trace with modifiers'] = array( |
171
|
|
|
'trace' => array_merge( |
172
|
|
|
array( |
173
|
|
|
$dumpframe + array( |
174
|
|
|
'file' => TestClass::DUMP_FILE, |
175
|
|
|
'line' => TestClass::DUMP_LINE + 1, |
176
|
|
|
), |
177
|
|
|
), |
178
|
|
|
$basetrace |
179
|
|
|
), |
180
|
|
|
'param_count' => 0, |
181
|
|
|
'expect' => array( |
182
|
|
|
array(), |
183
|
|
|
array('!', '+'), |
184
|
|
|
$dumpframe + array( |
185
|
|
|
'file' => TestClass::DUMP_FILE, |
186
|
|
|
'line' => TestClass::DUMP_LINE + 1, |
187
|
|
|
), |
188
|
|
|
), |
189
|
|
|
); |
190
|
|
|
|
191
|
|
|
$data['trace function with modifier'] = array( |
192
|
|
|
'trace' => array_merge( |
193
|
|
|
array( |
194
|
|
|
array( |
195
|
|
|
'function' => 'd', |
196
|
|
|
'file' => TestClass::DUMP_FILE, |
197
|
|
|
'line' => TestClass::DUMP_LINE + 2, |
198
|
|
|
), |
199
|
|
|
), |
200
|
|
|
$basetrace |
201
|
|
|
), |
202
|
|
|
'param_count' => 1, |
203
|
|
|
'expect' => array( |
204
|
|
|
array( |
205
|
|
|
array( |
206
|
|
|
'name' => '$x', |
207
|
|
|
'path' => '$x', |
208
|
|
|
'expression' => false, |
209
|
|
|
), |
210
|
|
|
), |
211
|
|
|
array('~'), |
212
|
|
|
array( |
213
|
|
|
'function' => 'd', |
214
|
|
|
'file' => TestClass::DUMP_FILE, |
215
|
|
|
'line' => TestClass::DUMP_LINE + 2, |
216
|
|
|
), |
217
|
|
|
), |
218
|
|
|
); |
219
|
|
|
|
220
|
|
|
// HHVM doesn't support multiple unpack parameters |
221
|
|
|
if (KINT_PHP56 && !defined('HHVM_VERSION')) { |
222
|
|
|
$data['trace with unpack'] = array( |
223
|
|
|
'trace' => array_merge( |
224
|
|
|
array( |
225
|
|
|
$dumpframe + array( |
226
|
|
|
'file' => Php56TestClass::DUMP_FILE, |
227
|
|
|
'line' => Php56TestClass::DUMP_LINE, |
228
|
|
|
), |
229
|
|
|
), |
230
|
|
|
$basetrace |
231
|
|
|
), |
232
|
|
|
'param_count' => 4, |
233
|
|
|
'expect' => array( |
234
|
|
|
array( |
235
|
|
|
array( |
236
|
|
|
'name' => '$x', |
237
|
|
|
'path' => '$x', |
238
|
|
|
'expression' => false, |
239
|
|
|
), |
240
|
|
|
array( |
241
|
|
|
'name' => '$y', |
242
|
|
|
'path' => '$y', |
243
|
|
|
'expression' => false, |
244
|
|
|
), |
245
|
|
|
array( |
246
|
|
|
'name' => 'reset($z)', |
247
|
|
|
'path' => 'reset($z)', |
248
|
|
|
'expression' => false, |
249
|
|
|
), |
250
|
|
|
array( |
251
|
|
|
'name' => 'array_values($z)[1]', |
252
|
|
|
'path' => 'array_values($z)[1]', |
253
|
|
|
'expression' => false, |
254
|
|
|
), |
255
|
|
|
), |
256
|
|
|
array(), |
257
|
|
|
$dumpframe + array( |
258
|
|
|
'file' => Php56TestClass::DUMP_FILE, |
259
|
|
|
'line' => Php56TestClass::DUMP_LINE, |
260
|
|
|
), |
261
|
|
|
), |
262
|
|
|
); |
263
|
|
|
|
264
|
|
|
$data['trace with double unpack'] = array( |
265
|
|
|
'trace' => array_merge( |
266
|
|
|
array( |
267
|
|
|
$dumpframe + array( |
268
|
|
|
'file' => Php56TestClass::DUMP_FILE, |
269
|
|
|
'line' => Php56TestClass::DUMP_LINE + 1, |
270
|
|
|
), |
271
|
|
|
), |
272
|
|
|
$basetrace |
273
|
|
|
), |
274
|
|
|
'param_count' => 10, |
275
|
|
|
'expect' => array( |
276
|
|
|
array(), |
277
|
|
|
array(), |
278
|
|
|
$dumpframe + array( |
279
|
|
|
'file' => Php56TestClass::DUMP_FILE, |
280
|
|
|
'line' => Php56TestClass::DUMP_LINE + 1, |
281
|
|
|
), |
282
|
|
|
), |
283
|
|
|
); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
return $data; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @dataProvider getCalleeInfoProvider |
291
|
|
|
* @covers \Kint\Kint::getCalleeInfo |
292
|
|
|
*/ |
293
|
|
|
public function testGetCalleeInfo($trace, $param_count, $expect) |
|
|
|
|
294
|
|
|
{ |
295
|
|
|
$func = new ReflectionMethod('Kint', 'getCalleeInfo'); |
296
|
|
|
$func->setAccessible(true); |
297
|
|
|
|
298
|
|
|
$output = $func->invoke(null, $trace, $param_count); |
|
|
|
|
299
|
|
|
|
300
|
|
|
$output = array_slice($output, 0, count($expect)); |
301
|
|
|
|
302
|
|
|
$this->assertSame($expect, $output); |
303
|
|
|
} |
304
|
|
|
} |
305
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.