1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Kint_Object_MethodTest extends PHPUnit_Framework_TestCase |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
public function testConstruct() |
6
|
|
|
{ |
7
|
|
|
$reflection = new ReflectionMethod('TestClass', 'mix'); |
8
|
|
|
$m = new Kint_Object_Method($reflection); |
|
|
|
|
9
|
|
|
$this->assertEquals('mix', $m->name); |
10
|
|
|
$this->assertEquals($reflection->getFilename(), $m->filename); |
11
|
|
|
$this->assertEquals($reflection->getStartLine(), $m->startline); |
12
|
|
|
$this->assertEquals($reflection->getEndLine(), $m->endline); |
13
|
|
|
$this->assertEquals(false, $m->internal); |
14
|
|
|
$this->assertEquals($reflection->getDocComment(), $m->docstring); |
15
|
|
|
$this->assertEquals(Kint_Object::OPERATOR_STATIC, $m->operator); |
16
|
|
|
$this->assertEquals(Kint_Object::ACCESS_PROTECTED, $m->access); |
17
|
|
|
$this->assertEquals('TestClass', $m->owner_class); |
18
|
|
|
$this->assertTrue($m->static); |
19
|
|
|
$this->assertTrue($m->final); |
20
|
|
|
$this->assertFalse($m->abstract); |
21
|
|
|
$this->assertFalse($m->internal); |
22
|
|
|
|
23
|
|
|
$reflection = new ReflectionMethod('ChildTestClass', '__construct'); |
24
|
|
|
$parent_reflection = new ReflectionMethod('TestClass', '__construct'); |
|
|
|
|
25
|
|
|
$m = new Kint_Object_Method($reflection); |
26
|
|
|
$this->assertEquals($parent_reflection->getDocComment(), $m->docstring); |
|
|
|
|
27
|
|
|
$this->assertEquals(Kint_Object::OPERATOR_OBJECT, $m->operator); |
28
|
|
|
$this->assertEquals(Kint_Object::ACCESS_PUBLIC, $m->access); |
29
|
|
|
$this->assertEquals('TestClass', $m->owner_class); |
30
|
|
|
|
31
|
|
|
$reflection = new ReflectionFunction('explode'); |
32
|
|
|
$m = new Kint_Object_Method($reflection); |
33
|
|
|
$this->assertTrue($m->internal); |
34
|
|
|
$this->assertEquals(Kint_Object::OPERATOR_NONE, $m->operator); |
35
|
|
|
$this->assertEquals(Kint_Object::ACCESS_NONE, $m->access); |
36
|
|
|
$this->assertEquals(null, $m->owner_class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @expectedException \InvalidArgumentException |
41
|
|
|
*/ |
42
|
|
|
public function testConstructWrongType() |
43
|
|
|
{ |
44
|
|
|
$m = new Kint_Object_Method(new stdClass()); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testSetAccessPathFrom() |
48
|
|
|
{ |
49
|
|
|
$o = Kint_Object::blank('$tc'); |
|
|
|
|
50
|
|
|
$o = $o->transplant(new Kint_Object_Instance()); |
51
|
|
|
$o->classname = 'TestClass'; |
|
|
|
|
52
|
|
|
|
53
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__construct')); |
|
|
|
|
54
|
|
|
$this->assertNull($m->getAccessPath()); |
55
|
|
|
$m->setAccessPathFrom($o); |
|
|
|
|
56
|
|
|
$this->assertEquals('new \\TestClass()', $m->getAccessPath()); |
57
|
|
|
|
58
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'static_method')); |
59
|
|
|
$this->assertNull($m->getAccessPath()); |
60
|
|
|
$m->setAccessPathFrom($o); |
|
|
|
|
61
|
|
|
$this->assertEquals('\\TestClass::static_method()', $m->getAccessPath()); |
62
|
|
|
|
63
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'final_method')); |
64
|
|
|
$this->assertNull($m->getAccessPath()); |
65
|
|
|
$m->setAccessPathFrom($o); |
|
|
|
|
66
|
|
|
$this->assertEquals('$tc->final_method()', $m->getAccessPath()); |
67
|
|
|
|
68
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'mix')); |
69
|
|
|
$this->assertNull($m->getAccessPath()); |
70
|
|
|
$m->setAccessPathFrom($o); |
|
|
|
|
71
|
|
|
$this->assertEquals( |
72
|
|
|
'\\TestClass::mix(array &$x, TestClass $y = null, $z = array(...), $_ = \'string\')', |
73
|
|
|
$m->getAccessPath() |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__clone')); |
77
|
|
|
$this->assertNull($m->getAccessPath()); |
78
|
|
|
$m->setAccessPathFrom($o); |
|
|
|
|
79
|
|
|
$this->assertEquals('clone $tc', $m->getAccessPath()); |
80
|
|
|
|
81
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__invoke')); |
82
|
|
|
$this->assertNull($m->getAccessPath()); |
83
|
|
|
$m->setAccessPathFrom($o); |
|
|
|
|
84
|
|
|
$this->assertEquals('$tc($x)', $m->getAccessPath()); |
85
|
|
|
|
86
|
|
|
// Tests both tostring and case insensitivity |
87
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__tostring')); |
88
|
|
|
$this->assertNull($m->getAccessPath()); |
89
|
|
|
$m->setAccessPathFrom($o); |
|
|
|
|
90
|
|
|
$this->assertEquals('__ToStRiNg', $m->name); |
91
|
|
|
$this->assertEquals('(string) $tc', $m->getAccessPath()); |
92
|
|
|
|
93
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__get')); |
94
|
|
|
$this->assertNull($m->getAccessPath()); |
95
|
|
|
$m->setAccessPathFrom($o); |
|
|
|
|
96
|
|
|
$this->assertNull($m->getAccessPath()); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testGetValueShort() |
100
|
|
|
{ |
101
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__construct')); |
|
|
|
|
102
|
|
|
$this->assertEquals( |
103
|
|
|
'This is a constructor for a TestClass with the first line of the docstring split into two different lines.', |
104
|
|
|
$m->getValueShort() |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testGetModifiers() |
109
|
|
|
{ |
110
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'static_method')); |
|
|
|
|
111
|
|
|
$this->assertEquals('private static', $m->getModifiers()); |
112
|
|
|
|
113
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'final_method')); |
114
|
|
|
$this->assertEquals('final public', $m->getModifiers()); |
115
|
|
|
|
116
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('ReflectionFunctionAbstract', '__toString')); |
117
|
|
|
$this->assertEquals('abstract public', $m->getModifiers()); |
118
|
|
|
|
119
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'mix')); |
120
|
|
|
$this->assertEquals('final protected static', $m->getModifiers()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testGetAccessPath() |
124
|
|
|
{ |
125
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'array_hint')); |
|
|
|
|
126
|
|
|
$this->assertNull($m->getAccessPath()); |
127
|
|
|
$m->access_path = '$m->array_hint'; |
128
|
|
|
$this->assertEquals('$m->array_hint(array $x)', $m->getAccessPath()); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function testGetParams() |
132
|
|
|
{ |
133
|
|
|
$m = new Kint_Object_Method(new ReflectionFunction('explode')); |
|
|
|
|
134
|
|
|
if (defined('HHVM_VERSION')) { |
135
|
|
|
$this->assertStringStartsWith('HH\\string $delimiter, HH\\string $str, HH\\int $limit = ', $m->getParams()); |
136
|
|
|
} else { |
137
|
|
|
$this->assertEquals('$separator, $str, $limit', $m->getParams()); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'array_hint')); |
141
|
|
|
$this->assertEquals('array $x', $m->getParams()); |
142
|
|
|
|
143
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'class_hint')); |
144
|
|
|
$this->assertEquals('TestClass $x', $m->getParams()); |
145
|
|
|
|
146
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'ref')); |
147
|
|
|
$this->assertEquals('&$x', $m->getParams()); |
148
|
|
|
|
149
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'default_method')); |
150
|
|
|
$this->assertEquals('$x = 1234', $m->getParams()); |
151
|
|
|
|
152
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'mix')); |
153
|
|
|
$this->assertEquals( |
154
|
|
|
'array &$x, TestClass $y = null, $z = array(...), $_ = \'string\'', |
155
|
|
|
$m->getParams() |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testGetPhpDocUrl() |
160
|
|
|
{ |
161
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('ReflectionMethod', '__construct')); |
|
|
|
|
162
|
|
|
$this->assertEquals( |
163
|
|
|
'https://secure.php.net/reflectionmethod.construct', |
164
|
|
|
$m->getPhpDocUrl() |
165
|
|
|
); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function testGetPhpDocUrlParent() |
169
|
|
|
{ |
170
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod('ReflectionMethod', '__clone')); |
|
|
|
|
171
|
|
|
$this->assertEquals( |
172
|
|
|
'https://secure.php.net/reflectionfunctionabstract.clone', |
173
|
|
|
$m->getPhpDocUrl() |
174
|
|
|
); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function testGetPhpDocUrlUserDefined() |
178
|
|
|
{ |
179
|
|
|
$m = new Kint_Object_Method(new ReflectionMethod(__CLASS__, __FUNCTION__)); |
|
|
|
|
180
|
|
|
$this->assertNull($m->getPhpDocUrl()); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
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.