|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class KintTest extends KintTestCase |
|
4
|
|
|
{ |
|
5
|
|
|
public function testSettings() |
|
6
|
|
|
{ |
|
7
|
|
|
$r = new ReflectionClass('Kint'); |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
$props = $r->getProperties(ReflectionProperty::IS_STATIC); |
|
10
|
|
|
$props_array = array(); |
|
|
|
|
|
|
11
|
|
|
foreach ($props as $prop) { |
|
12
|
|
|
if ($prop->isPublic() && $prop->isStatic()) { |
|
13
|
|
|
$props_array[$prop->getName()] = $prop->getValue(); |
|
|
|
|
|
|
14
|
|
|
} |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
$props = $r->getStaticProperties(); |
|
18
|
|
|
|
|
19
|
|
|
$this->assertEquals($props_array, $stash = Kint::settings()); |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
$props_array['enabled_mode'] = Kint::$enabled_mode = false; |
|
|
|
|
|
|
22
|
|
|
$props_array['file_link_format'] = Kint::$file_link_format = 'linky'; |
|
|
|
|
|
|
23
|
|
|
$props_array['app_root_dirs'] = Kint::$app_root_dirs = array('/' => '<fsroot>'); |
|
|
|
|
|
|
24
|
|
|
$props_array['max_depth'] = Kint::$max_depth = 0; |
|
|
|
|
|
|
25
|
|
|
$props_array['expanded'] = Kint::$expanded = true; |
|
|
|
|
|
|
26
|
|
|
$props_array['cli_detection'] = Kint::$cli_detection = false; |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
$this->assertNotEquals($props, $r->getStaticProperties()); |
|
29
|
|
|
$this->assertEquals($props_array, Kint::settings($stash)); |
|
|
|
|
|
|
30
|
|
|
$this->assertEquals($props, $r->getStaticProperties()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function pathProvider() |
|
34
|
|
|
{ |
|
35
|
|
|
return array( |
|
36
|
|
|
'standard file' => array( |
|
37
|
|
|
'path' => __FILE__, |
|
38
|
|
|
'expect' => '<tests>/KintTest.php', |
|
39
|
|
|
), |
|
40
|
|
|
'standard dir' => array( |
|
41
|
|
|
'path' => __DIR__, |
|
42
|
|
|
'expect' => '<tests>', |
|
43
|
|
|
), |
|
44
|
|
|
'parent dir' => array( |
|
45
|
|
|
'path' => KINT_DIR, |
|
46
|
|
|
'expect' => '<kint>', |
|
47
|
|
|
), |
|
48
|
|
|
'sub file' => array( |
|
49
|
|
|
'path' => KINT_DIR.'/src//test', |
|
50
|
|
|
'expect' => '<kint>/src/test', |
|
51
|
|
|
), |
|
52
|
|
|
'common path' => array( |
|
53
|
|
|
'path' => dirname(KINT_DIR).'/test/', |
|
54
|
|
|
'expect' => '.../test', |
|
55
|
|
|
), |
|
56
|
|
|
'root path' => array( |
|
57
|
|
|
'path' => '/', |
|
58
|
|
|
'expect' => '/', |
|
59
|
|
|
), |
|
60
|
|
|
'no common path' => array( |
|
61
|
|
|
'path' => '/asdfasdf/test/', |
|
62
|
|
|
'expect' => '/asdfasdf/test', |
|
63
|
|
|
), |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @dataProvider pathProvider |
|
69
|
|
|
*/ |
|
70
|
|
|
public function testShortenPath($path, $expect) |
|
71
|
|
|
{ |
|
72
|
|
|
Kint::$app_root_dirs = array( |
|
73
|
|
|
KINT_DIR => '<kint>', |
|
74
|
|
|
KINT_DIR.'/test' => '<test>', |
|
75
|
|
|
__DIR__ => '<tests>', |
|
76
|
|
|
KINT_DIR.'/tes' => '<tes>', |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertEquals($expect, Kint::shortenPath($path)); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testGetIdeLink() |
|
83
|
|
|
{ |
|
84
|
|
|
Kint::$file_link_format = '<a href="%f:%l">%f:%l</a>'; |
|
85
|
|
|
|
|
86
|
|
|
$file = uniqid('', true); |
|
87
|
|
|
$line = uniqid('', true); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertEquals('<a href="'.$file.':'.$line.'">'.$file.':'.$line.'</a>', Kint::getIdeLink($file, $line)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function setUp() |
|
93
|
|
|
{ |
|
94
|
|
|
parent::setUp(); |
|
95
|
|
|
|
|
96
|
|
|
if ($this->getName() === 'testComposerGetExtras' && !getenv('KINT_FILE')) { |
|
97
|
|
|
rename(KINT_DIR.'/composer.json', KINT_DIR.'/composer.json.bak'); |
|
98
|
|
|
|
|
99
|
|
|
file_put_contents(KINT_DIR.'/composer.json', json_encode(array( |
|
100
|
|
|
'extra' => array( |
|
101
|
|
|
'kint' => array('test' => 'data'), |
|
102
|
|
|
), |
|
103
|
|
|
))); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function tearDown() |
|
108
|
|
|
{ |
|
109
|
|
|
parent::tearDown(); |
|
110
|
|
|
|
|
111
|
|
|
if ($this->getName() === 'testComposerGetExtras' && !getenv('KINT_FILE')) { |
|
112
|
|
|
rename(KINT_DIR.'/composer.json.bak', KINT_DIR.'/composer.json'); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Test Kint::composerGetExtras. |
|
118
|
|
|
* |
|
119
|
|
|
* This is a flimsy test but it's as good as it gets without altering |
|
120
|
|
|
* composer.json mid-test without a proper setup/teardown in place |
|
121
|
|
|
*/ |
|
122
|
|
|
public function testComposerGetExtras() |
|
123
|
|
|
{ |
|
124
|
|
|
if (getenv('KINT_FILE')) { |
|
125
|
|
|
$this->markTestSkipped('Not testing composerGetExtras in single file build'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
$this->assertEquals(array('test' => 'data'), Kint::composerGetExtras('kint')); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
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.