|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kint\Test\Parser; |
|
4
|
|
|
|
|
5
|
|
|
use Kint\Object\BasicObject; |
|
6
|
|
|
use Kint\Parser\Parser; |
|
7
|
|
|
use Kint\Parser\TracePlugin; |
|
8
|
|
|
use PHPUnit_Framework_TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class TracePluginTest extends PHPUnit_Framework_TestCase |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
protected $blacklist_stash; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @covers \Kint\Parser\TracePlugin::parse |
|
16
|
|
|
*/ |
|
17
|
|
|
public function testParse() |
|
18
|
|
|
{ |
|
19
|
|
|
$p = new Parser(); |
|
|
|
|
|
|
20
|
|
|
$p->addPlugin(new TracePlugin()); |
|
21
|
|
|
|
|
22
|
|
|
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
$o = BasicObject::blank(); |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
$o = $p->parse($bt, $o); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertContains('trace', $o->hints); |
|
29
|
|
|
$this->assertInstanceOf('Kint\\Object\\TraceObject', $o); |
|
30
|
|
|
$this->assertInstanceOf('Kint\\Object\\TraceFrameObject', $o->value->contents[0]); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @covers \Kint\Parser\TracePlugin::parse |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testParseMismatch() |
|
37
|
|
|
{ |
|
38
|
|
|
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
|
|
|
|
|
39
|
|
|
$b = BasicObject::blank(); |
|
|
|
|
|
|
40
|
|
|
$parser = new Parser(); |
|
41
|
|
|
$plugin = new TracePlugin(); |
|
42
|
|
|
|
|
43
|
|
|
$incorrect = $parser->parse($bt, clone $b); |
|
44
|
|
|
$incorrect->value->contents[0]->name = 'newName'; |
|
45
|
|
|
$parser->addPlugin($plugin); |
|
46
|
|
|
$plugin->parse($bt, $incorrect, Parser::TRIGGER_SUCCESS); |
|
47
|
|
|
|
|
48
|
|
|
array_shift($bt); |
|
49
|
|
|
$correct = $parser->parse($bt, clone $b); |
|
50
|
|
|
|
|
51
|
|
|
foreach ($correct->value->contents as $frame) { |
|
52
|
|
|
++$frame->name; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$this->assertEquals($correct, $incorrect); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @covers \Kint\Parser\TracePlugin::parse |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testParseNoValue() |
|
62
|
|
|
{ |
|
63
|
|
|
$p = new TracePlugin(); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$b = BasicObject::blank(); |
|
|
|
|
|
|
66
|
|
|
$o = clone $b; |
|
|
|
|
|
|
67
|
|
|
$v = array(); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
$p->parse($v, $o, Parser::TRIGGER_SUCCESS); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertEquals($b, $o); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @covers \Kint\Parser\TracePlugin::parse |
|
76
|
|
|
*/ |
|
77
|
|
|
public function testParseBlacklist() |
|
78
|
|
|
{ |
|
79
|
|
|
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
|
|
|
|
|
80
|
|
|
$shortbt = $bt; |
|
81
|
|
|
array_shift($shortbt); |
|
82
|
|
|
|
|
83
|
|
|
$p = new Parser(); |
|
|
|
|
|
|
84
|
|
|
$p->addPlugin(new TracePlugin()); |
|
85
|
|
|
|
|
86
|
|
|
$b = BasicObject::blank(); |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
$o = $p->parse($shortbt, clone $b); |
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
foreach ($o->value->contents as $frame) { |
|
91
|
|
|
++$frame->name; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
TracePlugin::$blacklist[] = array(__CLASS__, __FUNCTION__); |
|
95
|
|
|
|
|
96
|
|
|
$this->assertEquals($o->value, $p->parse($bt, clone $b)->value); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function provideTraces() |
|
100
|
|
|
{ |
|
101
|
|
|
$bt = debug_backtrace(true); |
|
|
|
|
|
|
102
|
|
|
$bad_bt_1 = $bt; |
|
|
|
|
|
|
103
|
|
|
$bad_bt_1[0]['test'] = 'woot'; |
|
|
|
|
|
|
104
|
|
|
$bad_bt_2 = $bt; |
|
|
|
|
|
|
105
|
|
|
$bad_bt_2[0]['function'] = 1234; |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
return array( |
|
108
|
|
|
'empty' => array( |
|
109
|
|
|
'trace' => array(), |
|
110
|
|
|
'expect' => false, |
|
111
|
|
|
), |
|
112
|
|
|
'backtrace' => array( |
|
113
|
|
|
'trace' => $bt, |
|
114
|
|
|
'expect' => true, |
|
115
|
|
|
), |
|
116
|
|
|
'bad backtrace, extra key' => array( |
|
117
|
|
|
'trace' => $bad_bt_1, |
|
|
|
|
|
|
118
|
|
|
'expect' => false, |
|
119
|
|
|
), |
|
120
|
|
|
'bad backtrace, wrong type' => array( |
|
121
|
|
|
'trace' => $bad_bt_2, |
|
|
|
|
|
|
122
|
|
|
'expect' => false, |
|
123
|
|
|
), |
|
124
|
|
|
'mythical' => array( |
|
125
|
|
|
'trace' => array( |
|
126
|
|
|
array( |
|
127
|
|
|
'function' => 'mythical_internal_function_with_no_args_that_results_in_a_backtrace', |
|
128
|
|
|
'file' => __FILE__, |
|
129
|
|
|
'line' => 1, |
|
130
|
|
|
), |
|
131
|
|
|
), |
|
132
|
|
|
'expect' => true, |
|
133
|
|
|
), |
|
134
|
|
|
'normal array' => array( |
|
135
|
|
|
'trace' => array(1, 2, 3), |
|
136
|
|
|
'expect' => false, |
|
137
|
|
|
), |
|
138
|
|
|
); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @dataProvider provideTraces |
|
143
|
|
|
* @covers \Kint\Parser\TracePlugin::isTrace |
|
144
|
|
|
*/ |
|
145
|
|
|
public function testIsTrace(array $trace, $expected) |
|
146
|
|
|
{ |
|
147
|
|
|
$this->assertEquals($expected, TracePlugin::isTrace($trace)); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function provideFrames() |
|
151
|
|
|
{ |
|
152
|
|
|
return array( |
|
153
|
|
|
'function match' => array( |
|
154
|
|
|
'frame' => array( |
|
155
|
|
|
'function' => 'testAWeirdFunctionName', |
|
156
|
|
|
), |
|
157
|
|
|
'matches' => array('testaweirdfunctionname'), |
|
158
|
|
|
'expected' => true, |
|
159
|
|
|
), |
|
160
|
|
|
'function no match denormalized' => array( |
|
161
|
|
|
'frame' => array( |
|
162
|
|
|
'function' => 'testAWeirdFunctionName', |
|
163
|
|
|
), |
|
164
|
|
|
'matches' => array('testAWeirdFunctionName'), |
|
165
|
|
|
'expected' => false, |
|
166
|
|
|
), |
|
167
|
|
|
'function no match method' => array( |
|
168
|
|
|
'frame' => array( |
|
169
|
|
|
'function' => 'testAWeirdFunctionName', |
|
170
|
|
|
), |
|
171
|
|
|
'matches' => array(array('test', 'testaweirdfunctionname')), |
|
172
|
|
|
'expected' => false, |
|
173
|
|
|
), |
|
174
|
|
|
'method no match function' => array( |
|
175
|
|
|
'frame' => array( |
|
176
|
|
|
'function' => 'testAWeirdFunctionName', |
|
177
|
|
|
'class' => 'test', |
|
178
|
|
|
), |
|
179
|
|
|
'matches' => array('testAWeirdFunctionName'), |
|
180
|
|
|
'expected' => false, |
|
181
|
|
|
), |
|
182
|
|
|
'method match' => array( |
|
183
|
|
|
'frame' => array( |
|
184
|
|
|
'function' => 'testAWeirdFunctionName', |
|
185
|
|
|
'class' => 'test', |
|
186
|
|
|
), |
|
187
|
|
|
'matches' => array(array('test', 'testaweirdfunctionname')), |
|
188
|
|
|
'expected' => true, |
|
189
|
|
|
), |
|
190
|
|
|
); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @dataProvider provideFrames |
|
195
|
|
|
* @covers \Kint\Parser\TracePlugin::frameIsListed |
|
196
|
|
|
*/ |
|
197
|
|
|
public function testFrameIsListed(array $frame, array $matches, $expected) |
|
198
|
|
|
{ |
|
199
|
|
|
$this->assertEquals($expected, TracePlugin::frameIsListed($frame, $matches)); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @covers \Kint\Parser\TracePlugin::normalizeAliases |
|
204
|
|
|
*/ |
|
205
|
|
|
public function testNormalizeAliases() |
|
206
|
|
|
{ |
|
207
|
|
|
$input = array( |
|
208
|
|
|
'CamelCaseFunction', |
|
209
|
|
|
'snake_case_function', |
|
210
|
|
|
'One_of_the_FunctionsMyColleaguesMADE__', |
|
211
|
|
|
'stringThatCan\'tBeAfunction', |
|
212
|
|
|
'another string that can not be a function', |
|
213
|
|
|
array('clASs', 'meThod'), |
|
214
|
|
|
array($this, 'meThod'), |
|
215
|
|
|
array('a', 'b', 'c'), |
|
216
|
|
|
); |
|
217
|
|
|
|
|
218
|
|
|
$expected = array( |
|
219
|
|
|
'camelcasefunction', |
|
220
|
|
|
'snake_case_function', |
|
221
|
|
|
'one_of_the_functionsmycolleaguesmade__', |
|
222
|
|
|
array('class', 'method'), |
|
223
|
|
|
); |
|
224
|
|
|
|
|
225
|
|
|
TracePlugin::normalizeAliases($input); |
|
226
|
|
|
|
|
227
|
|
|
$this->assertEquals($expected, $input); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @covers \Kint\Parser\TracePlugin::getTypes |
|
232
|
|
|
* @covers \Kint\Parser\TracePlugin::getTriggers |
|
233
|
|
|
*/ |
|
234
|
|
|
public function testHooks() |
|
235
|
|
|
{ |
|
236
|
|
|
$p = new TracePlugin(); |
|
|
|
|
|
|
237
|
|
|
|
|
238
|
|
|
$this->assertEquals(array('array'), $p->getTypes()); |
|
239
|
|
|
$this->assertEquals(Parser::TRIGGER_SUCCESS, $p->getTriggers()); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
public function setUp() |
|
243
|
|
|
{ |
|
244
|
|
|
$this->blacklist_stash = TracePlugin::$blacklist; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
public function tearDown() |
|
248
|
|
|
{ |
|
249
|
|
|
TracePlugin::$blacklist = $this->blacklist_stash; |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
|
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.