1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kint\Test; |
4
|
|
|
|
5
|
|
|
use 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
|
|
|
protected $composer_stash; |
|
|
|
|
15
|
|
|
protected $installed_stash; |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @covers \Kint::settings |
19
|
|
|
*/ |
20
|
|
|
public function testSettings() |
21
|
|
|
{ |
22
|
|
|
$r = new ReflectionClass('Kint'); |
|
|
|
|
23
|
|
|
|
24
|
|
|
$props = $r->getProperties(ReflectionProperty::IS_STATIC); |
25
|
|
|
$props_array = array(); |
|
|
|
|
26
|
|
|
foreach ($props as $prop) { |
27
|
|
|
if ($prop->isPublic() && $prop->isStatic()) { |
28
|
|
|
$props_array[$prop->getName()] = $prop->getValue(); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$props = $r->getStaticProperties(); |
33
|
|
|
|
34
|
|
|
$this->assertEquals($props_array, $stash = Kint::settings()); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$props_array['enabled_mode'] = Kint::$enabled_mode = false; |
|
|
|
|
37
|
|
|
$props_array['file_link_format'] = Kint::$file_link_format = 'linky'; |
|
|
|
|
38
|
|
|
$props_array['app_root_dirs'] = Kint::$app_root_dirs = array('/' => '<fsroot>'); |
|
|
|
|
39
|
|
|
$props_array['max_depth'] = Kint::$max_depth = 0; |
|
|
|
|
40
|
|
|
$props_array['expanded'] = Kint::$expanded = true; |
|
|
|
|
41
|
|
|
$props_array['cli_detection'] = Kint::$cli_detection = false; |
|
|
|
|
42
|
|
|
|
43
|
|
|
$this->assertNotEquals($props, $r->getStaticProperties()); |
44
|
|
|
$this->assertEquals($props_array, Kint::settings($stash)); |
|
|
|
|
45
|
|
|
$this->assertEquals($props, $r->getStaticProperties()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function pathProvider() |
49
|
|
|
{ |
50
|
|
|
return array( |
51
|
|
|
'standard file' => array( |
52
|
|
|
'path' => __FILE__, |
53
|
|
|
'expect' => '<tests>/KintTest.php', |
54
|
|
|
), |
55
|
|
|
'standard dir' => array( |
56
|
|
|
'path' => __DIR__, |
57
|
|
|
'expect' => '<tests>', |
58
|
|
|
), |
59
|
|
|
'parent dir' => array( |
60
|
|
|
'path' => KINT_DIR, |
61
|
|
|
'expect' => '<kint>', |
62
|
|
|
), |
63
|
|
|
'sub file' => array( |
64
|
|
|
'path' => KINT_DIR.'/src//test', |
65
|
|
|
'expect' => '<kint>/src/test', |
66
|
|
|
), |
67
|
|
|
'common path' => array( |
68
|
|
|
'path' => dirname(KINT_DIR).'/test/', |
69
|
|
|
'expect' => '.../test', |
70
|
|
|
), |
71
|
|
|
'root path' => array( |
72
|
|
|
'path' => '/', |
73
|
|
|
'expect' => '/', |
74
|
|
|
), |
75
|
|
|
'no common path' => array( |
76
|
|
|
'path' => '/asdfasdf/test/', |
77
|
|
|
'expect' => '/asdfasdf/test', |
78
|
|
|
), |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @dataProvider pathProvider |
84
|
|
|
* @covers \Kint::shortenPath |
85
|
|
|
*/ |
86
|
|
|
public function testShortenPath($path, $expect) |
87
|
|
|
{ |
88
|
|
|
Kint::$app_root_dirs = array( |
89
|
|
|
KINT_DIR => '<kint>', |
90
|
|
|
KINT_DIR.'/test' => '<test>', |
91
|
|
|
'' => '<Nothing!>', |
92
|
|
|
__DIR__ => '<tests>', |
93
|
|
|
KINT_DIR.'/tes' => '<tes>', |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$this->assertEquals($expect, Kint::shortenPath($path)); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @covers \Kint::getIdeLink |
101
|
|
|
*/ |
102
|
|
|
public function testGetIdeLink() |
103
|
|
|
{ |
104
|
|
|
Kint::$file_link_format = '<a href="%f:%l">%f:%l</a>'; |
105
|
|
|
|
106
|
|
|
$file = uniqid('', true); |
107
|
|
|
$line = uniqid('', true); |
108
|
|
|
|
109
|
|
|
$this->assertEquals('<a href="'.$file.':'.$line.'">'.$file.':'.$line.'</a>', Kint::getIdeLink($file, $line)); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function setUp() |
113
|
|
|
{ |
114
|
|
|
parent::setUp(); |
115
|
|
|
|
116
|
|
|
if (!getenv('KINT_FILE')) { |
117
|
|
|
$this->composer_stash = file_get_contents(KINT_DIR.'/composer.json'); |
118
|
|
|
$this->installed_stash = file_get_contents(KINT_DIR.'/vendor/composer/installed.json'); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function tearDown() |
123
|
|
|
{ |
124
|
|
|
parent::tearDown(); |
125
|
|
|
|
126
|
|
|
if ($this->composer_stash) { |
127
|
|
|
file_put_contents(KINT_DIR.'/composer.json', $this->composer_stash); |
128
|
|
|
file_put_contents(KINT_DIR.'/vendor/composer/installed.json', $this->installed_stash); |
129
|
|
|
$this->composer_stash = null; |
130
|
|
|
$this->installed_stash = null; |
131
|
|
|
if (file_exists(KINT_DIR.'/composer/installed.json')) { |
132
|
|
|
unlink(KINT_DIR.'/composer/installed.json'); |
133
|
|
|
} |
134
|
|
|
if (file_exists(KINT_DIR.'/composer')) { |
135
|
|
|
rmdir(KINT_DIR.'/composer'); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Test Kint::composerGetExtras. |
142
|
|
|
* |
143
|
|
|
* This is a flimsy test but it's as good as it gets without altering |
144
|
|
|
* composer.json mid-test without a proper setup/teardown in place |
145
|
|
|
* |
146
|
|
|
* @covers \Kint::composerGetExtras |
147
|
|
|
*/ |
148
|
|
|
public function testComposerGetExtras() |
149
|
|
|
{ |
150
|
|
|
if (getenv('KINT_FILE')) { |
151
|
|
|
$this->markTestSkipped('Not testing composerGetExtras in single file build'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
file_put_contents(KINT_DIR.'/composer.json', json_encode(array( |
155
|
|
|
'extra' => array( |
156
|
|
|
'kint' => array('test' => 'data'), |
157
|
|
|
), |
158
|
|
|
))); |
159
|
|
|
|
160
|
|
|
$this->assertEquals(array('test' => 'data'), Kint::composerGetExtras('kint')); |
161
|
|
|
|
162
|
|
|
mkdir(KINT_DIR.'/composer'); |
163
|
|
|
unlink(KINT_DIR.'/vendor/composer/installed.json'); |
164
|
|
|
|
165
|
|
|
file_put_contents(KINT_DIR.'/composer/installed.json', json_encode(array( |
166
|
|
|
array( |
167
|
|
|
'extra' => array( |
168
|
|
|
'kint' => array('more' => 'test', 'data'), |
169
|
|
|
), |
170
|
|
|
), |
171
|
|
|
array( |
172
|
|
|
'extra' => array( |
173
|
|
|
'kint' => array('test' => 'ing'), |
174
|
|
|
), |
175
|
|
|
), |
176
|
|
|
))); |
177
|
|
|
|
178
|
|
|
$this->assertEquals(array('more' => 'test', 'data', 'test' => 'ing'), Kint::composerGetExtras('kint')); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @covers \Kint::composerGetDisableHelperFunctions |
183
|
|
|
*/ |
184
|
|
|
public function testComposerGetDisableHelperFunctions() |
185
|
|
|
{ |
186
|
|
|
if (getenv('KINT_FILE')) { |
187
|
|
|
$this->markTestSkipped('Not testing composerGetDisableHelperFunctions in single file build'); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
$this->assertFalse(Kint::composerGetDisableHelperFunctions()); |
191
|
|
|
|
192
|
|
|
file_put_contents(KINT_DIR.'/composer.json', json_encode(array( |
193
|
|
|
'extra' => array( |
194
|
|
|
'kint' => array('disable-helper-functions' => true), |
195
|
|
|
), |
196
|
|
|
))); |
197
|
|
|
|
198
|
|
|
$this->assertTrue(Kint::composerGetDisableHelperFunctions()); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function getCalleeInfoProvider() |
202
|
|
|
{ |
203
|
|
|
$basetrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
204
|
|
|
$dumpframe = array( |
205
|
|
|
'class' => 'Kint', |
206
|
|
|
'function' => 'dump', |
207
|
|
|
); |
208
|
|
|
|
209
|
|
|
$data['empty trace'] = array( |
|
|
|
|
210
|
|
|
'trace' => array( |
211
|
|
|
), |
212
|
|
|
'param_count' => 1234, |
213
|
|
|
'expect' => array( |
214
|
|
|
null, |
215
|
|
|
array(), |
216
|
|
|
null, |
217
|
|
|
null, |
218
|
|
|
array(), |
219
|
|
|
), |
220
|
|
|
); |
221
|
|
|
|
222
|
|
|
$data['full trace'] = array( |
223
|
|
|
'trace' => array_merge(array($dumpframe), $basetrace), |
224
|
|
|
'param_count' => 1234, |
225
|
|
|
'expect' => array( |
226
|
|
|
null, |
227
|
|
|
array(), |
228
|
|
|
$dumpframe, |
229
|
|
|
array( |
230
|
|
|
'function' => __FUNCTION__, |
231
|
|
|
'class' => __CLASS__, |
232
|
|
|
'type' => '->', |
233
|
|
|
), |
234
|
|
|
), |
235
|
|
|
); |
236
|
|
|
|
237
|
|
|
$data['trace with params'] = array( |
238
|
|
|
'trace' => array_merge( |
239
|
|
|
array( |
240
|
|
|
$dumpframe + array( |
241
|
|
|
'file' => TestClass::DUMP_FILE, |
242
|
|
|
'line' => TestClass::DUMP_LINE, |
243
|
|
|
), |
244
|
|
|
), |
245
|
|
|
$basetrace |
246
|
|
|
), |
247
|
|
|
'param_count' => 3, |
248
|
|
|
'expect' => array( |
249
|
|
|
array( |
250
|
|
|
array('name' => '$x', 'path' => '$x', 'expression' => false), |
251
|
|
|
array('name' => '$y', 'path' => '$y', 'expression' => false), |
252
|
|
|
array('name' => '$z', 'path' => '$z', 'expression' => false), |
253
|
|
|
), |
254
|
|
|
array(), |
255
|
|
|
$dumpframe + array( |
256
|
|
|
'file' => TestClass::DUMP_FILE, |
257
|
|
|
'line' => TestClass::DUMP_LINE, |
258
|
|
|
), |
259
|
|
|
), |
260
|
|
|
); |
261
|
|
|
|
262
|
|
|
$data['trace with modifiers'] = array( |
263
|
|
|
'trace' => array_merge( |
264
|
|
|
array( |
265
|
|
|
$dumpframe + array( |
266
|
|
|
'file' => TestClass::DUMP_FILE, |
267
|
|
|
'line' => TestClass::DUMP_LINE + 1, |
268
|
|
|
), |
269
|
|
|
), |
270
|
|
|
$basetrace |
271
|
|
|
), |
272
|
|
|
'param_count' => 0, |
273
|
|
|
'expect' => array( |
274
|
|
|
array(), |
275
|
|
|
array('!', '+'), |
276
|
|
|
$dumpframe + array( |
277
|
|
|
'file' => TestClass::DUMP_FILE, |
278
|
|
|
'line' => TestClass::DUMP_LINE + 1, |
279
|
|
|
), |
280
|
|
|
), |
281
|
|
|
); |
282
|
|
|
|
283
|
|
|
$data['trace function with modifier'] = array( |
284
|
|
|
'trace' => array_merge( |
285
|
|
|
array( |
286
|
|
|
array( |
287
|
|
|
'function' => 'd', |
288
|
|
|
'file' => TestClass::DUMP_FILE, |
289
|
|
|
'line' => TestClass::DUMP_LINE + 2, |
290
|
|
|
), |
291
|
|
|
), |
292
|
|
|
$basetrace |
293
|
|
|
), |
294
|
|
|
'param_count' => 1, |
295
|
|
|
'expect' => array( |
296
|
|
|
array( |
297
|
|
|
array( |
298
|
|
|
'name' => '$x', |
299
|
|
|
'path' => '$x', |
300
|
|
|
'expression' => false, |
301
|
|
|
), |
302
|
|
|
), |
303
|
|
|
array('~'), |
304
|
|
|
array( |
305
|
|
|
'function' => 'd', |
306
|
|
|
'file' => TestClass::DUMP_FILE, |
307
|
|
|
'line' => TestClass::DUMP_LINE + 2, |
308
|
|
|
), |
309
|
|
|
), |
310
|
|
|
); |
311
|
|
|
|
312
|
|
|
// HHVM doesn't support multiple unpack parameters |
313
|
|
|
if (KINT_PHP56 && !defined('HHVM_VERSION')) { |
314
|
|
|
$data['trace with unpack'] = array( |
315
|
|
|
'trace' => array_merge( |
316
|
|
|
array( |
317
|
|
|
$dumpframe + array( |
318
|
|
|
'file' => Php56TestClass::DUMP_FILE, |
319
|
|
|
'line' => Php56TestClass::DUMP_LINE, |
320
|
|
|
), |
321
|
|
|
), |
322
|
|
|
$basetrace |
323
|
|
|
), |
324
|
|
|
'param_count' => 4, |
325
|
|
|
'expect' => array( |
326
|
|
|
array( |
327
|
|
|
array( |
328
|
|
|
'name' => '$x', |
329
|
|
|
'path' => '$x', |
330
|
|
|
'expression' => false, |
331
|
|
|
), |
332
|
|
|
array( |
333
|
|
|
'name' => '$y', |
334
|
|
|
'path' => '$y', |
335
|
|
|
'expression' => false, |
336
|
|
|
), |
337
|
|
|
array( |
338
|
|
|
'name' => 'reset($z)', |
339
|
|
|
'path' => 'reset($z)', |
340
|
|
|
'expression' => false, |
341
|
|
|
), |
342
|
|
|
array( |
343
|
|
|
'name' => 'array_values($z)[1]', |
344
|
|
|
'path' => 'array_values($z)[1]', |
345
|
|
|
'expression' => false, |
346
|
|
|
), |
347
|
|
|
), |
348
|
|
|
array(), |
349
|
|
|
$dumpframe + array( |
350
|
|
|
'file' => Php56TestClass::DUMP_FILE, |
351
|
|
|
'line' => Php56TestClass::DUMP_LINE, |
352
|
|
|
), |
353
|
|
|
), |
354
|
|
|
); |
355
|
|
|
|
356
|
|
|
$data['trace with double unpack'] = array( |
357
|
|
|
'trace' => array_merge( |
358
|
|
|
array( |
359
|
|
|
$dumpframe + array( |
360
|
|
|
'file' => Php56TestClass::DUMP_FILE, |
361
|
|
|
'line' => Php56TestClass::DUMP_LINE + 1, |
362
|
|
|
), |
363
|
|
|
), |
364
|
|
|
$basetrace |
365
|
|
|
), |
366
|
|
|
'param_count' => 10, |
367
|
|
|
'expect' => array( |
368
|
|
|
array(), |
369
|
|
|
array(), |
370
|
|
|
$dumpframe + array( |
371
|
|
|
'file' => Php56TestClass::DUMP_FILE, |
372
|
|
|
'line' => Php56TestClass::DUMP_LINE + 1, |
373
|
|
|
), |
374
|
|
|
), |
375
|
|
|
); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
return $data; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* @dataProvider getCalleeInfoProvider |
383
|
|
|
* @covers \Kint::getCalleeInfo |
384
|
|
|
*/ |
385
|
|
|
public function testGetCalleeInfo($trace, $param_count, $expect) |
|
|
|
|
386
|
|
|
{ |
387
|
|
|
$func = new ReflectionMethod('Kint', 'getCalleeInfo'); |
388
|
|
|
$func->setAccessible(true); |
389
|
|
|
|
390
|
|
|
$output = $func->invoke(null, $trace, $param_count); |
|
|
|
|
391
|
|
|
|
392
|
|
|
$output = array_slice($output, 0, count($expect)); |
393
|
|
|
|
394
|
|
|
$this->assertSame($expect, $output); |
395
|
|
|
} |
396
|
|
|
} |
397
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.