|
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
|
|
|
/** |
|
100
|
|
|
* @covers \Kint\Parser\TracePlugin::getTypes |
|
101
|
|
|
* @covers \Kint\Parser\TracePlugin::getTriggers |
|
102
|
|
|
*/ |
|
103
|
|
|
public function testHooks() |
|
104
|
|
|
{ |
|
105
|
|
|
$p = new TracePlugin(); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
$this->assertEquals(array('array'), $p->getTypes()); |
|
108
|
|
|
$this->assertEquals(Parser::TRIGGER_SUCCESS, $p->getTriggers()); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function setUp() |
|
112
|
|
|
{ |
|
113
|
|
|
$this->blacklist_stash = TracePlugin::$blacklist; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function tearDown() |
|
117
|
|
|
{ |
|
118
|
|
|
TracePlugin::$blacklist = $this->blacklist_stash; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
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.