|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Kint_Parser_TraceTest extends PHPUnit_Framework_TestCase |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
public function testParse() |
|
6
|
|
|
{ |
|
7
|
|
|
$p = new Kint_Parser(); |
|
|
|
|
|
|
8
|
|
|
$p->addPlugin(new Kint_Parser_Trace()); |
|
9
|
|
|
|
|
10
|
|
|
$bt = defined('DEBUG_BACKTRACE_IGNORE_ARGS') |
|
|
|
|
|
|
11
|
|
|
? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) |
|
12
|
|
|
: debug_backtrace(); |
|
13
|
|
|
|
|
14
|
|
|
$o = Kint_Object::blank(); |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
$o = $p->parse($bt, $o); |
|
17
|
|
|
|
|
18
|
|
|
$this->assertContains('trace', $o->hints); |
|
19
|
|
|
$this->assertInstanceOf('Kint_Object_Trace', $o); |
|
20
|
|
|
$this->assertInstanceOf('Kint_Object_TraceFrame', $o->value->contents[0]); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function provideTraces() |
|
24
|
|
|
{ |
|
25
|
|
|
$bt = debug_backtrace(true); |
|
|
|
|
|
|
26
|
|
|
$bad_bt_1 = $bt; |
|
|
|
|
|
|
27
|
|
|
$bad_bt_1[0]['test'] = 'woot'; |
|
|
|
|
|
|
28
|
|
|
$bad_bt_2 = $bt; |
|
|
|
|
|
|
29
|
|
|
$bat_bt_2[0]['function'] = 1234; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
return array( |
|
32
|
|
|
'empty' => array( |
|
33
|
|
|
'trace' => array(), |
|
34
|
|
|
'expect' => false, |
|
35
|
|
|
), |
|
36
|
|
|
'backtrace' => array( |
|
37
|
|
|
'trace' => $bt, |
|
38
|
|
|
'expect' => true, |
|
39
|
|
|
), |
|
40
|
|
|
'bad backtrace, extra key' => array( |
|
41
|
|
|
'trace' => $bad_bt_1, |
|
|
|
|
|
|
42
|
|
|
'expect' => false, |
|
43
|
|
|
), |
|
44
|
|
|
'bad backtrace, wrong type' => array( |
|
45
|
|
|
'trace' => $bad_bt_1, |
|
|
|
|
|
|
46
|
|
|
'expect' => false, |
|
47
|
|
|
), |
|
48
|
|
|
'mythical' => array( |
|
49
|
|
|
'trace' => array( |
|
50
|
|
|
array( |
|
51
|
|
|
'function' => 'mythical_internal_function_with_no_args_that_results_in_a_backtrace', |
|
52
|
|
|
'file' => __FILE__, |
|
53
|
|
|
'line' => 1, |
|
54
|
|
|
), |
|
55
|
|
|
), |
|
56
|
|
|
'expect' => true, |
|
57
|
|
|
), |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @dataProvider provideTraces |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testIsTrace(array $trace, $expected) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->assertEquals($expected, Kint_Parser_Trace::isTrace($trace)); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function provideFrames() |
|
70
|
|
|
{ |
|
71
|
|
|
return array( |
|
72
|
|
|
'function match' => array( |
|
73
|
|
|
'frame' => array( |
|
74
|
|
|
'function' => 'testAWeirdFunctionName', |
|
75
|
|
|
), |
|
76
|
|
|
'matches' => array('testaweirdfunctionname'), |
|
77
|
|
|
'expected' => true, |
|
78
|
|
|
), |
|
79
|
|
|
'function no match denormalized' => array( |
|
80
|
|
|
'frame' => array( |
|
81
|
|
|
'function' => 'testAWeirdFunctionName', |
|
82
|
|
|
), |
|
83
|
|
|
'matches' => array('testAWeirdFunctionName'), |
|
84
|
|
|
'expected' => false, |
|
85
|
|
|
), |
|
86
|
|
|
'function no match method' => array( |
|
87
|
|
|
'frame' => array( |
|
88
|
|
|
'function' => 'testAWeirdFunctionName', |
|
89
|
|
|
), |
|
90
|
|
|
'matches' => array(array('test', 'testaweirdfunctionname')), |
|
91
|
|
|
'expected' => false, |
|
92
|
|
|
), |
|
93
|
|
|
'method no match function' => array( |
|
94
|
|
|
'frame' => array( |
|
95
|
|
|
'function' => 'testAWeirdFunctionName', |
|
96
|
|
|
'class' => 'test', |
|
97
|
|
|
), |
|
98
|
|
|
'matches' => array('testAWeirdFunctionName'), |
|
99
|
|
|
'expected' => false, |
|
100
|
|
|
), |
|
101
|
|
|
'method match' => array( |
|
102
|
|
|
'frame' => array( |
|
103
|
|
|
'function' => 'testAWeirdFunctionName', |
|
104
|
|
|
'class' => 'test', |
|
105
|
|
|
), |
|
106
|
|
|
'matches' => array(array('test', 'testaweirdfunctionname')), |
|
107
|
|
|
'expected' => true, |
|
108
|
|
|
), |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @dataProvider provideFrames |
|
114
|
|
|
*/ |
|
115
|
|
|
public function testFrameIsListed(array $frame, array $matches, $expected) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->assertEquals($expected, Kint_Parser_Trace::frameIsListed($frame, $matches)); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function testNormalizeAliases() |
|
121
|
|
|
{ |
|
122
|
|
|
$input = array( |
|
123
|
|
|
'CamelCaseFunction', |
|
124
|
|
|
'snake_case_function', |
|
125
|
|
|
'One_of_the_FunctionsMyColleaguesMADE__', |
|
126
|
|
|
'stringThatCan\'tBeAfunction', |
|
127
|
|
|
'another string that can not be a function', |
|
128
|
|
|
array('clASs', 'meThod'), |
|
129
|
|
|
array($this, 'meThod'), |
|
130
|
|
|
array('a', 'b', 'c'), |
|
131
|
|
|
); |
|
132
|
|
|
|
|
133
|
|
|
$expected = array( |
|
134
|
|
|
'camelcasefunction', |
|
135
|
|
|
'snake_case_function', |
|
136
|
|
|
'one_of_the_functionsmycolleaguesmade__', |
|
137
|
|
|
array('class', 'method'), |
|
138
|
|
|
); |
|
139
|
|
|
|
|
140
|
|
|
Kint_Parser_Trace::normalizeAliases($input); |
|
141
|
|
|
|
|
142
|
|
|
$this->assertEquals($expected, $input); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.