1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kint\Test\Object; |
4
|
|
|
|
5
|
|
|
use Kint\Object\BasicObject; |
6
|
|
|
use Kint\Object\Representation\Representation; |
7
|
|
|
|
8
|
|
|
class BasicObjectTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @covers \Kint\Object\BasicObject::__construct |
12
|
|
|
* @covers \Kint\Object\BasicObject::getRepresentations |
13
|
|
|
* @covers \Kint\Object\BasicObject::addRepresentation |
14
|
|
|
*/ |
15
|
|
|
public function testAddRepresentation() |
16
|
|
|
{ |
17
|
|
|
$o = new BasicObject(); |
|
|
|
|
18
|
|
|
|
19
|
|
|
$this->assertSame(array(), $o->getRepresentations()); |
20
|
|
|
$this->assertSame(null, $o->value); |
21
|
|
|
|
22
|
|
|
$this->assertTrue($o->addRepresentation($r1 = new Representation('Rep 1'))); |
23
|
|
|
$this->assertSame( |
24
|
|
|
array( |
25
|
|
|
'rep_1' => $r1, |
26
|
|
|
), |
27
|
|
|
$o->getRepresentations() |
28
|
|
|
); |
29
|
|
|
$this->assertSame(null, $o->value); |
30
|
|
|
|
31
|
|
|
$this->assertFalse($o->addRepresentation($r1)); |
32
|
|
|
$this->assertSame( |
33
|
|
|
array( |
34
|
|
|
'rep_1' => $r1, |
35
|
|
|
), |
36
|
|
|
$o->getRepresentations() |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$this->assertTrue($o->addRepresentation($r2 = new Representation('Rep 2'))); |
40
|
|
|
$this->assertSame( |
41
|
|
|
array( |
42
|
|
|
'rep_1' => $r1, |
43
|
|
|
'rep_2' => $r2, |
44
|
|
|
), |
45
|
|
|
$o->getRepresentations() |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->assertTrue($o->addRepresentation($r3 = new Representation('Rep 3'), 0)); |
49
|
|
|
$this->assertSame( |
50
|
|
|
array( |
51
|
|
|
'rep_3' => $r3, |
52
|
|
|
'rep_1' => $r1, |
53
|
|
|
'rep_2' => $r2, |
54
|
|
|
), |
55
|
|
|
$o->getRepresentations() |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$this->assertTrue($o->addRepresentation($r4 = new Representation('Rep 4'), 1)); |
59
|
|
|
$this->assertSame( |
60
|
|
|
array( |
61
|
|
|
'rep_3' => $r3, |
62
|
|
|
'rep_4' => $r4, |
63
|
|
|
'rep_1' => $r1, |
64
|
|
|
'rep_2' => $r2, |
65
|
|
|
), |
66
|
|
|
$o->getRepresentations() |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$this->assertTrue($o->addRepresentation($r5 = new Representation('Rep 5'), 100)); |
70
|
|
|
$this->assertSame( |
71
|
|
|
array( |
72
|
|
|
'rep_3' => $r3, |
73
|
|
|
'rep_4' => $r4, |
74
|
|
|
'rep_1' => $r1, |
75
|
|
|
'rep_2' => $r2, |
76
|
|
|
'rep_5' => $r5, |
77
|
|
|
), |
78
|
|
|
$o->getRepresentations() |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$this->assertTrue($o->addRepresentation($r6 = new Representation('Rep 6'), -100)); |
82
|
|
|
$this->assertSame( |
83
|
|
|
array( |
84
|
|
|
'rep_6' => $r6, |
85
|
|
|
'rep_3' => $r3, |
86
|
|
|
'rep_4' => $r4, |
87
|
|
|
'rep_1' => $r1, |
88
|
|
|
'rep_2' => $r2, |
89
|
|
|
'rep_5' => $r5, |
90
|
|
|
), |
91
|
|
|
$o->getRepresentations() |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$this->assertSame(null, $o->value); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @covers \Kint\Object\BasicObject::replaceRepresentation |
99
|
|
|
*/ |
100
|
|
|
public function testReplaceRepresentation() |
101
|
|
|
{ |
102
|
|
|
$o = new BasicObject(); |
|
|
|
|
103
|
|
|
$o->addRepresentation($r1 = new Representation('Rep 1')); |
104
|
|
|
$o->addRepresentation($r2 = new Representation('Rep 2')); |
105
|
|
|
$o->addRepresentation($r3 = new Representation('Rep 3')); |
106
|
|
|
|
107
|
|
|
$this->assertSame( |
108
|
|
|
array( |
109
|
|
|
'rep_1' => $r1, |
110
|
|
|
'rep_2' => $r2, |
111
|
|
|
'rep_3' => $r3, |
112
|
|
|
), |
113
|
|
|
$o->getRepresentations() |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
$o->replaceRepresentation($r2_2 = new Representation('Rep 2')); |
|
|
|
|
117
|
|
|
|
118
|
|
|
$this->assertSame( |
119
|
|
|
array( |
120
|
|
|
'rep_1' => $r1, |
121
|
|
|
'rep_2' => $r2_2, |
|
|
|
|
122
|
|
|
'rep_3' => $r3, |
123
|
|
|
), |
124
|
|
|
$o->getRepresentations() |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
$o->replaceRepresentation($r2, 0); |
128
|
|
|
|
129
|
|
|
$this->assertSame( |
130
|
|
|
array( |
131
|
|
|
'rep_2' => $r2, |
132
|
|
|
'rep_1' => $r1, |
133
|
|
|
'rep_3' => $r3, |
134
|
|
|
), |
135
|
|
|
$o->getRepresentations() |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
$o->replaceRepresentation($r2_2, 1); |
|
|
|
|
139
|
|
|
|
140
|
|
|
$this->assertSame( |
141
|
|
|
array( |
142
|
|
|
'rep_1' => $r1, |
143
|
|
|
'rep_2' => $r2_2, |
|
|
|
|
144
|
|
|
'rep_3' => $r3, |
145
|
|
|
), |
146
|
|
|
$o->getRepresentations() |
147
|
|
|
); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @covers \Kint\Object\BasicObject::removeRepresentation |
152
|
|
|
*/ |
153
|
|
|
public function testRemoveRepresentation() |
154
|
|
|
{ |
155
|
|
|
$o = new BasicObject(); |
|
|
|
|
156
|
|
|
$o->addRepresentation($r1 = new Representation('Rep 1')); |
157
|
|
|
$o->addRepresentation($r2 = new Representation('Rep 2')); |
158
|
|
|
$o->addRepresentation($r3 = new Representation('Rep 3')); |
159
|
|
|
|
160
|
|
|
$this->assertSame( |
161
|
|
|
array( |
162
|
|
|
'rep_1' => $r1, |
163
|
|
|
'rep_2' => $r2, |
164
|
|
|
'rep_3' => $r3, |
165
|
|
|
), |
166
|
|
|
$o->getRepresentations() |
167
|
|
|
); |
168
|
|
|
|
169
|
|
|
$o->removeRepresentation('rep_2'); |
170
|
|
|
|
171
|
|
|
$this->assertSame( |
172
|
|
|
array( |
173
|
|
|
'rep_1' => $r1, |
174
|
|
|
'rep_3' => $r3, |
175
|
|
|
), |
176
|
|
|
$o->getRepresentations() |
177
|
|
|
); |
178
|
|
|
|
179
|
|
|
$o->removeRepresentation($r1); |
180
|
|
|
$this->assertSame(array('rep_3' => $r3), $o->getRepresentations()); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @covers \Kint\Object\BasicObject::getRepresentation |
185
|
|
|
*/ |
186
|
|
|
public function testGetRepresentation() |
187
|
|
|
{ |
188
|
|
|
$o = new BasicObject(); |
|
|
|
|
189
|
|
|
$o->addRepresentation($r1 = new Representation('Rep 1')); |
190
|
|
|
$o->addRepresentation($r2 = new Representation('Rep 2')); |
191
|
|
|
$o->addRepresentation($r3 = new Representation('Rep 3')); |
192
|
|
|
|
193
|
|
|
$this->assertSame($r1, $o->getRepresentation('rep_1')); |
194
|
|
|
$this->assertSame($r2, $o->getRepresentation('rep_2')); |
195
|
|
|
$this->assertSame($r3, $o->getRepresentation('rep_3')); |
196
|
|
|
$this->assertSame(null, $o->getRepresentation('Non-existant representation name')); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @covers \Kint\Object\BasicObject::getRepresentations |
201
|
|
|
*/ |
202
|
|
|
public function testGetRepresentations() |
203
|
|
|
{ |
204
|
|
|
$o = new BasicObject(); |
|
|
|
|
205
|
|
|
$o->addRepresentation($r1 = new Representation('Rep 1')); |
206
|
|
|
$o->addRepresentation($r2 = new Representation('Rep 2')); |
207
|
|
|
$o->addRepresentation($r3 = new Representation('Rep 3')); |
208
|
|
|
|
209
|
|
|
$this->assertSame( |
210
|
|
|
array( |
211
|
|
|
'rep_1' => $r1, |
212
|
|
|
'rep_2' => $r2, |
213
|
|
|
'rep_3' => $r3, |
214
|
|
|
), |
215
|
|
|
$o->getRepresentations() |
216
|
|
|
); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @covers \Kint\Object\BasicObject::clearRepresentations |
221
|
|
|
*/ |
222
|
|
|
public function testClearRepresentations() |
223
|
|
|
{ |
224
|
|
|
$o = new BasicObject(); |
|
|
|
|
225
|
|
|
$o->addRepresentation($r1 = new Representation('Rep 1')); |
226
|
|
|
$o->addRepresentation(new Representation('Rep 2')); |
227
|
|
|
$o->addRepresentation(new Representation('Rep 3')); |
228
|
|
|
$o->value = $r1; |
229
|
|
|
|
230
|
|
|
$o->clearRepresentations(); |
231
|
|
|
|
232
|
|
|
$this->assertSame(array(), $o->getRepresentations()); |
233
|
|
|
$this->assertSame($r1, $o->value); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @covers \Kint\Object\BasicObject::getType |
238
|
|
|
*/ |
239
|
|
|
public function testGetType() |
240
|
|
|
{ |
241
|
|
|
$o = new BasicObject(); |
|
|
|
|
242
|
|
|
$o->type = 'array'; |
243
|
|
|
$this->assertEquals('array', $o->getType()); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
public function modifierProvider() |
247
|
|
|
{ |
248
|
|
|
return array( |
249
|
|
|
'public' => array( |
250
|
|
|
false, |
251
|
|
|
false, |
252
|
|
|
BasicObject::ACCESS_PUBLIC, |
253
|
|
|
'public', |
254
|
|
|
), |
255
|
|
|
'public const' => array( |
256
|
|
|
true, |
257
|
|
|
false, |
258
|
|
|
BasicObject::ACCESS_PUBLIC, |
259
|
|
|
'public const', |
260
|
|
|
), |
261
|
|
|
'public static' => array( |
262
|
|
|
false, |
263
|
|
|
true, |
264
|
|
|
BasicObject::ACCESS_PUBLIC, |
265
|
|
|
'public static', |
266
|
|
|
), |
267
|
|
|
'protected' => array( |
268
|
|
|
false, |
269
|
|
|
false, |
270
|
|
|
BasicObject::ACCESS_PROTECTED, |
271
|
|
|
'protected', |
272
|
|
|
), |
273
|
|
|
'private' => array( |
274
|
|
|
false, |
275
|
|
|
false, |
276
|
|
|
BasicObject::ACCESS_PRIVATE, |
277
|
|
|
'private', |
278
|
|
|
), |
279
|
|
|
'none' => array( |
280
|
|
|
false, |
281
|
|
|
false, |
282
|
|
|
BasicObject::ACCESS_NONE, |
283
|
|
|
null, |
284
|
|
|
), |
285
|
|
|
'private static' => array( |
286
|
|
|
false, |
287
|
|
|
true, |
288
|
|
|
BasicObject::ACCESS_PRIVATE, |
289
|
|
|
'private static', |
290
|
|
|
), |
291
|
|
|
'public const static' => array( |
292
|
|
|
true, |
293
|
|
|
true, |
294
|
|
|
BasicObject::ACCESS_PUBLIC, |
295
|
|
|
'public const static', |
296
|
|
|
), |
297
|
|
|
'const' => array( |
298
|
|
|
true, |
299
|
|
|
false, |
300
|
|
|
BasicObject::ACCESS_NONE, |
301
|
|
|
'const', |
302
|
|
|
), |
303
|
|
|
); |
304
|
|
|
$accesses = array( |
|
|
|
|
305
|
|
|
BasicObject::ACCESS_NONE, |
306
|
|
|
BasicObject::ACCESS_PUBLIC, |
307
|
|
|
BasicObject::ACCESS_PROTECTED, |
308
|
|
|
BasicObject::ACCESS_PRIVATE, |
309
|
|
|
); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @dataProvider modifierProvider |
314
|
|
|
* @covers \Kint\Object\BasicObject::getModifiers |
315
|
|
|
*/ |
316
|
|
|
public function testGetModifiers($const, $static, $access, $expect) |
317
|
|
|
{ |
318
|
|
|
$o = new BasicObject(); |
|
|
|
|
319
|
|
|
$o->const = $const; |
320
|
|
|
$o->static = $static; |
321
|
|
|
$o->access = $access; |
322
|
|
|
$this->assertSame($expect, $o->getModifiers()); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @covers \Kint\Object\BasicObject::getAccess |
327
|
|
|
*/ |
328
|
|
|
public function testGetAccess() |
329
|
|
|
{ |
330
|
|
|
$o = new BasicObject(); |
|
|
|
|
331
|
|
|
$this->assertNull($o->getAccess()); |
332
|
|
|
$o->access = BasicObject::ACCESS_PUBLIC; |
333
|
|
|
$this->assertEquals('public', $o->getAccess()); |
334
|
|
|
$o->access = BasicObject::ACCESS_PROTECTED; |
335
|
|
|
$this->assertEquals('protected', $o->getAccess()); |
336
|
|
|
$o->access = BasicObject::ACCESS_PRIVATE; |
337
|
|
|
$this->assertEquals('private', $o->getAccess()); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @covers \Kint\Object\BasicObject::getName |
342
|
|
|
*/ |
343
|
|
View Code Duplication |
public function testGetName() |
|
|
|
|
344
|
|
|
{ |
345
|
|
|
$o = new BasicObject(); |
|
|
|
|
346
|
|
|
$o->name = '$var'; |
347
|
|
|
$this->assertEquals('$var', $o->getName()); |
348
|
|
|
$o->name = '($a + $b)'; |
349
|
|
|
$this->assertEquals('($a + $b)', $o->getName()); |
350
|
|
|
$o->name = 'This is just a name, nothing more, nothing less.'; |
351
|
|
|
$this->assertEquals('This is just a name, nothing more, nothing less.', $o->getName()); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @covers \Kint\Object\BasicObject::getOperator |
356
|
|
|
*/ |
357
|
|
|
public function testGetOperator() |
358
|
|
|
{ |
359
|
|
|
$o = new BasicObject(); |
|
|
|
|
360
|
|
|
$this->assertNull($o->getOperator()); |
361
|
|
|
$o->operator = BasicObject::OPERATOR_NONE; |
362
|
|
|
$this->assertNull($o->getOperator()); |
363
|
|
|
$o->operator = BasicObject::OPERATOR_ARRAY; |
364
|
|
|
$this->assertEquals('=>', $o->getOperator()); |
365
|
|
|
$o->operator = BasicObject::OPERATOR_OBJECT; |
366
|
|
|
$this->assertEquals('->', $o->getOperator()); |
367
|
|
|
$o->operator = BasicObject::OPERATOR_STATIC; |
368
|
|
|
$this->assertEquals('::', $o->getOperator()); |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* @covers \Kint\Object\BasicObject::getSize |
373
|
|
|
*/ |
374
|
|
View Code Duplication |
public function testGetSize() |
|
|
|
|
375
|
|
|
{ |
376
|
|
|
$o = new BasicObject(); |
|
|
|
|
377
|
|
|
$this->assertNull($o->getSize()); |
378
|
|
|
$o->size = 0; |
379
|
|
|
$this->assertEquals(0, $o->getSize()); |
380
|
|
|
$o->size = 42; |
381
|
|
|
$this->assertEquals(42, $o->getSize()); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @covers \Kint\Object\BasicObject::getValueShort |
386
|
|
|
*/ |
387
|
|
|
public function testGetValueShort() |
388
|
|
|
{ |
389
|
|
|
$o = new BasicObject(); |
|
|
|
|
390
|
|
|
$r = new Representation('contents'); |
|
|
|
|
391
|
|
|
$this->assertNull($o->getValueShort()); |
392
|
|
|
$o->value = $r; |
393
|
|
|
|
394
|
|
|
$r->contents = true; |
|
|
|
|
395
|
|
|
$this->assertNull($o->getValueShort()); |
396
|
|
|
$o->type = 'boolean'; |
397
|
|
|
$this->assertEquals('true', $o->getValueShort()); |
398
|
|
|
$r->contents = false; |
|
|
|
|
399
|
|
|
$this->assertEquals('false', $o->getValueShort()); |
400
|
|
|
$o->type = 'integer'; |
401
|
|
|
$r->contents = 1234; |
|
|
|
|
402
|
|
|
$this->assertEquals(1234, $o->getValueShort()); |
403
|
|
|
$o->type = 'double'; |
404
|
|
|
$r->contents = 1234.5678; |
|
|
|
|
405
|
|
|
$this->assertEquals(1234.5678, $o->getValueShort()); |
406
|
|
|
$o->type = 'array'; |
407
|
|
|
$r->contents = array(); |
408
|
|
|
$this->assertNull($o->getValueShort()); |
409
|
|
|
$o->type = 'string'; |
410
|
|
|
$r->contents = 'string'; |
|
|
|
|
411
|
|
|
$this->assertNull($o->getValueShort()); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* @covers \Kint\Object\BasicObject::getAccessPath |
416
|
|
|
*/ |
417
|
|
|
public function testGetAccessPath() |
418
|
|
|
{ |
419
|
|
|
$o = new BasicObject(); |
|
|
|
|
420
|
|
|
$this->assertNull($o->getAccessPath()); |
421
|
|
|
$o->access_path = 'abcdefg, hijk elemeno p'; |
422
|
|
|
$this->assertEquals('abcdefg, hijk elemeno p', $o->getAccessPath()); |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* @covers \Kint\Object\BasicObject::blank |
427
|
|
|
*/ |
428
|
|
|
public function testBlank() |
429
|
|
|
{ |
430
|
|
|
$o = new BasicObject(); |
|
|
|
|
431
|
|
|
$this->assertNull($o->name); |
432
|
|
|
$this->assertNull($o->access_path); |
433
|
|
|
|
434
|
|
|
$o = BasicObject::blank(); |
435
|
|
|
$this->assertNull($o->name); |
436
|
|
|
$this->assertNull($o->access_path); |
437
|
|
|
|
438
|
|
|
$o = BasicObject::blank('$var'); |
439
|
|
|
$this->assertEquals('$var', $o->name); |
440
|
|
|
$this->assertEquals('$var', $o->access_path); |
441
|
|
|
|
442
|
|
|
$o = BasicObject::blank('Name', 'access_path'); |
443
|
|
|
$this->assertEquals('Name', $o->name); |
444
|
|
|
$this->assertEquals('access_path', $o->access_path); |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* @covers \Kint\Object\BasicObject::transplant |
449
|
|
|
*/ |
450
|
|
|
public function testTransplant() |
451
|
|
|
{ |
452
|
|
|
$o = new BasicObject(); |
|
|
|
|
453
|
|
|
|
454
|
|
|
$o->name = 'name'; |
455
|
|
|
$o->size = 42; |
456
|
|
|
$o->access_path = 'access_path'; |
457
|
|
|
$o->access = BasicObject::ACCESS_PUBLIC; |
458
|
|
|
$o->static = true; |
459
|
|
|
$o->const = true; |
460
|
|
|
$o->type = 'type'; |
461
|
|
|
$o->depth = 43; |
462
|
|
|
$o->owner_class = 'owner_class'; |
463
|
|
|
$o->operator = BasicObject::OPERATOR_OBJECT; |
464
|
|
|
$o->reference = true; |
465
|
|
|
$o->hints = array('test', 'transplant', 'hints'); |
466
|
|
|
|
467
|
|
|
$r = new Representation('Test'); |
|
|
|
|
468
|
|
|
$o->addRepresentation($r); |
469
|
|
|
|
470
|
|
|
$o2 = $o->transplant(new BasicObject()); |
|
|
|
|
471
|
|
|
|
472
|
|
|
$this->assertEquals($o, $o2); |
473
|
|
|
$this->assertNotSame($o, $o2); |
474
|
|
|
$this->assertSame($o->value, $o2->value); |
475
|
|
|
|
476
|
|
|
$o2 = new BasicObject(); |
477
|
|
|
$r2 = new Representation('Test 2'); |
|
|
|
|
478
|
|
|
$o2->addRepresentation($r2); |
479
|
|
|
$o2->hints = array('test', 'thoroughly'); |
480
|
|
|
|
481
|
|
|
$o2 = $o->transplant($o2); |
482
|
|
|
|
483
|
|
|
$this->assertSame(array('test_2' => $r2, 'test' => $r), $o2->getRepresentations()); |
484
|
|
|
$this->assertSame(array('test', 'transplant', 'hints', 'test', 'thoroughly'), $o2->hints); |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* @covers \Kint\Object\BasicObject::isSequential |
489
|
|
|
*/ |
490
|
|
|
public function testIsSequential() |
491
|
|
|
{ |
492
|
|
|
$this->assertTrue(BasicObject::isSequential(array(1, 2, 3, 4))); |
493
|
|
|
$this->assertFalse(BasicObject::isSequential(array(0 => 1, 1 => 2, 3 => 3, 2 => 4))); |
494
|
|
|
$this->assertFalse(BasicObject::isSequential(array(0 => 1, 1 => 2, '02' => 3, 3 => 4))); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* @covers \Kint\Object\BasicObject::sortByAccess |
499
|
|
|
*/ |
500
|
|
|
public function testSortByAccess() |
501
|
|
|
{ |
502
|
|
|
$o1 = new BasicObject(); |
|
|
|
|
503
|
|
|
$o2 = new BasicObject(); |
|
|
|
|
504
|
|
|
$o3 = new BasicObject(); |
|
|
|
|
505
|
|
|
|
506
|
|
|
$a = array($o1, $o2, $o3); |
|
|
|
|
507
|
|
|
|
508
|
|
|
$o1->access = BasicObject::ACCESS_PRIVATE; |
509
|
|
|
$o2->access = BasicObject::ACCESS_PROTECTED; |
510
|
|
|
$o3->access = BasicObject::ACCESS_PUBLIC; |
511
|
|
|
|
512
|
|
|
$this->assertSame(array($o1, $o2, $o3), $a); |
513
|
|
|
|
514
|
|
|
usort($a, 'Kint\\Object\\BasicObject::sortByAccess'); |
515
|
|
|
$this->assertSame(array($o3, $o2, $o1), $a); |
516
|
|
|
|
517
|
|
|
$o1->access = BasicObject::ACCESS_PROTECTED; |
518
|
|
|
$o2->access = BasicObject::ACCESS_PRIVATE; |
519
|
|
|
|
520
|
|
|
usort($a, 'Kint\\Object\\BasicObject::sortByAccess'); |
521
|
|
|
$this->assertSame(array($o3, $o1, $o2), $a); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* @covers \Kint\Object\BasicObject::sortByName |
526
|
|
|
*/ |
527
|
|
|
public function testSortByName() |
528
|
|
|
{ |
529
|
|
|
$o1 = new BasicObject(); |
|
|
|
|
530
|
|
|
$o2 = new BasicObject(); |
|
|
|
|
531
|
|
|
$o3 = new BasicObject(); |
|
|
|
|
532
|
|
|
|
533
|
|
|
$a = array($o1, $o2, $o3); |
|
|
|
|
534
|
|
|
|
535
|
|
|
$o1->name = 'Name Z'; |
536
|
|
|
$o2->name = 'Name B'; |
537
|
|
|
$o3->name = 'Name A'; |
538
|
|
|
|
539
|
|
|
$this->assertSame(array($o1, $o2, $o3), $a); |
540
|
|
|
|
541
|
|
|
usort($a, 'Kint\\Object\\BasicObject::sortByName'); |
542
|
|
|
$this->assertSame(array($o3, $o2, $o1), $a); |
543
|
|
|
|
544
|
|
|
$o1->name = 'Name M'; |
545
|
|
|
$o2->name = 'Name Z2'; |
546
|
|
|
|
547
|
|
|
usort($a, 'Kint\\Object\\BasicObject::sortByName'); |
548
|
|
|
$this->assertSame(array($o3, $o1, $o2), $a); |
549
|
|
|
|
550
|
|
|
$o1->name = '123'; |
551
|
|
|
$o2->name = 123; |
552
|
|
|
|
553
|
|
|
usort($a, 'Kint\\Object\\BasicObject::sortByName'); |
554
|
|
|
$this->assertSame(array($o2, $o1, $o3), $a); |
555
|
|
|
} |
556
|
|
|
} |
557
|
|
|
|
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.