Test Setup Failed
Push — test ( 16e845...7a62bf )
by Jonathan
03:51
created

ParserTest::testSortObjectProperties()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 21
nc 1
nop 0
dl 0
loc 36
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Kint\Test\Parser;
4
5
use Exception;
6
use Kint\Object\BasicObject;
7
use Kint\Object\BlobObject;
8
use Kint\Object\InstanceObject;
9
use Kint\Object\Representation\Representation;
10
use Kint\Object\ResourceObject;
11
use Kint\Parser\Parser;
12
use Kint\Parser\ProxyPlugin;
13
use Kint\Test\Fixtures\ChildTestClass;
14
use PHPUnit_Framework_TestCase;
15
use ReflectionProperty;
16
use stdClass;
17
18
class ParserTest extends PHPUnit_Framework_TestCase
19
{
20
    public function testTriggerComplete()
21
    {
22
        $this->assertEquals(
23
            Parser::TRIGGER_SUCCESS |
24
            Parser::TRIGGER_DEPTH_LIMIT |
25
            Parser::TRIGGER_RECURSION,
26
            Parser::TRIGGER_COMPLETE
27
        );
28
    }
29
30
    /**
31
     * @covers \Kint\Parser\Parser::__construct
32
     * @covers \Kint\Parser\Parser::getDepthLimit
33
     * @covers \Kint\Parser\Parser::getCallerClass
34
     */
35
    public function testConstruct()
36
    {
37
        $marker = new ReflectionProperty('Kint\\Parser\\Parser', 'marker');
38
39
        $marker->setAccessible(true);
40
41
        $p1 = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p1. Configured minimum length is 3.

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.

Loading history...
42
43
        $this->assertFalse($p1->getDepthLimit());
44
        $this->assertNull($p1->getCallerClass());
45
46
        $p2 = new Parser(123, 'asdf');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p2. Configured minimum length is 3.

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.

Loading history...
47
48
        $this->assertSame(123, $p2->getDepthLimit());
49
        $this->assertSame('asdf', $p2->getCallerClass());
50
        $this->assertNotEquals($marker->getValue($p1), $marker->getValue($p2));
51
    }
52
53
    /**
54
     * @covers \Kint\Parser\Parser::parse
55
     * @covers \Kint\Parser\Parser::parseGeneric
56
     */
57
    public function testParseInteger()
58
    {
59
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
60
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
61
        $v = 1234;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
62
63
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
64
65
        $this->assertEquals('$v', $o->access_path);
66
        $this->assertEquals('$v', $o->name);
67
        $this->assertEquals('integer', $o->type);
68
        $this->assertEquals('Kint\\Object\\BasicObject', get_class($o));
69
        $this->assertEquals('Kint\\Object\\Representation\\Representation', get_class($o->value));
70
        $this->assertEquals(1234, $o->value->contents);
71
        $this->assertEquals(1234, $v);
72
        $this->assertEquals(0, $o->depth);
73
    }
74
75
    /**
76
     * @covers \Kint\Parser\Parser::parse
77
     * @covers \Kint\Parser\Parser::parseGeneric
78
     */
79
    public function testParseBoolean()
80
    {
81
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
82
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
83
        $v = true;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
84
85
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
86
87
        $this->assertEquals('boolean', $o->type);
88
        $this->assertEquals(true, $o->value->contents);
89
90
        $v = false;
91
92
        $o = $p->parse($v, clone $b);
93
94
        $this->assertEquals(false, $o->value->contents);
95
    }
96
97
    /**
98
     * @covers \Kint\Parser\Parser::parse
99
     * @covers \Kint\Parser\Parser::parseGeneric
100
     */
101
    public function testParseDouble()
102
    {
103
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
104
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
105
        $v = 1234.5678;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
106
107
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
108
109
        $this->assertEquals('double', $o->type);
110
        $this->assertEquals(1234.5678, $o->value->contents);
111
    }
112
113
    /**
114
     * @covers \Kint\Parser\Parser::parse
115
     * @covers \Kint\Parser\Parser::parseGeneric
116
     */
117
    public function testParseNull()
118
    {
119
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
120
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
121
        $v = null;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
122
123
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
124
125
        $this->assertEquals('null', $o->type);
126
        $this->assertEquals(null, $o->value->contents);
127
    }
128
129
    /**
130
     * @covers \Kint\Parser\Parser::parse
131
     * @covers \Kint\Parser\Parser::parseString
132
     */
133
    public function testParseString()
134
    {
135
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
136
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
137
        $v = 'The quick brown fox jumps over the lazy dog';
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
138
139
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
140
141
        $this->assertInstanceOf('Kint\\Object\\BlobObject', $o);
142
        if (!$o instanceof BlobObject) {
143
            return; // phpstan
144
        }
145
146
        $this->assertEquals('string', $o->type);
147
        $this->assertEquals($v, $o->value->contents);
148
        $this->assertEquals(true, $o->value->implicit_label);
149
        $this->assertEquals('ASCII', $o->encoding);
150
        $this->assertEquals(strlen($v), $o->size);
151
        $this->assertContains('string', $o->hints);
152
153
        // Apologies to Spanish programmers, Google made this sentence.
154
        $v = 'El zorro marrón rápido salta sobre el perro perezoso';
155
156
        $o = $p->parse($v, clone $b);
157
158
        $this->assertInstanceOf('Kint\\Object\\BlobObject', $o);
159
        if (!$o instanceof BlobObject) {
160
            return; // phpstan
161
        }
162
163
        $this->assertEquals($v, $o->value->contents);
164
        $this->assertEquals('UTF-8', $o->encoding);
165
        $this->assertEquals(mb_strlen($v, 'UTF-8'), $o->size);
166
        $this->assertNotEquals(strlen($v), $o->size);
167
    }
168
169
    /**
170
     * @covers \Kint\Parser\Parser::parse
171
     * @covers \Kint\Parser\Parser::parseResource
172
     */
173
    public function testParseResource()
174
    {
175
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
176
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
177
        $v = imagecreate(1, 1);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
178
179
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
180
181
        $this->assertInstanceOf('Kint\\Object\\ResourceObject', $o);
182
        if (!$o instanceof ResourceObject) {
183
            return; // phpstan
184
        }
185
186
        $this->assertEquals('resource', $o->type);
187
        $this->assertEquals(null, $o->value);
188
        $this->assertEquals('gd', $o->resource_type);
189
    }
190
191
    /**
192
     * @covers \Kint\Parser\Parser::parse
193
     * @covers \Kint\Parser\Parser::parseArray
194
     */
195
    public function testParseArray()
196
    {
197
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
198
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
199
        $v = array(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
200
            1234,
201
            'key' => 'value',
202
            1234 => 5678,
203
        );
204
205
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
206
207
        $this->assertEquals('array', $o->type);
208
209
        $val = array_values($o->value->contents);
210
211
        $this->assertEquals(0, $val[0]->name);
212
        $this->assertEquals(1234, $val[0]->value->contents);
213
        $this->assertEquals('$v[0]', $val[0]->access_path);
214
        $this->assertEquals(BasicObject::OPERATOR_ARRAY, $val[0]->operator);
215
        $this->assertEquals('key', $val[1]->name);
216
        $this->assertEquals('value', $val[1]->value->contents);
217
        $this->assertEquals('$v[\'key\']', $val[1]->access_path);
218
        $this->assertEquals(BasicObject::OPERATOR_ARRAY, $val[1]->operator);
219
        $this->assertEquals(1234, $val[2]->name);
220
        $this->assertEquals(5678, $val[2]->value->contents);
221
        $this->assertEquals('$v[1234]', $val[2]->access_path);
222
        $this->assertEquals(BasicObject::OPERATOR_ARRAY, $val[2]->operator);
223
224
        $v = array();
225
226
        $o = $p->parse($v, clone $b);
227
228
        $this->assertInstanceOf('Kint\\Object\\Representation\\Representation', $o->value);
229
        $this->assertCount(0, $o->value->contents);
230
    }
231
232
    /**
233
     * @covers \Kint\Parser\Parser::parse
234
     * @covers \Kint\Parser\Parser::parseObject
235
     */
236
    public function testParseObject()
237
    {
238
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
239
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
240
        $v = new ChildTestClass();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
241
242
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
243
244
        $this->assertInstanceOf('Kint\\Object\\InstanceObject', $o);
245
        if (!$o instanceof InstanceObject) {
246
            return; // phpstan
247
        }
248
249
        $this->assertEquals('object', $o->type);
250
        $this->assertEquals('Kint\\Test\\Fixtures\\ChildTestClass', $o->classname);
251
        $this->assertEquals(spl_object_hash($v), $o->hash);
252
        $this->assertContains('object', $o->hints);
253
254
        $val = array_values($o->value->contents);
255
256
        $this->assertEquals('pub', $val[0]->name);
257
        $this->assertEquals('array', $val[0]->type);
258
        $this->assertEquals(BasicObject::OPERATOR_OBJECT, $val[0]->operator);
259
        $this->assertEquals('$v->pub', $val[0]->access_path);
260
        $this->assertEquals('pro', $val[1]->name);
261
        $this->assertEquals('array', $val[1]->type);
262
        $this->assertEquals(BasicObject::OPERATOR_OBJECT, $val[1]->operator);
263
        $this->assertNull($val[1]->access_path);
264
        $this->assertEquals('pri', $val[2]->name);
265
        $this->assertEquals('array', $val[2]->type);
266
        $this->assertEquals(BasicObject::OPERATOR_OBJECT, $val[2]->operator);
267
        $this->assertNull($val[2]->access_path);
268
    }
269
270
    /**
271
     * @covers \Kint\Parser\Parser::parse
272
     * @covers \Kint\Parser\Parser::parseUnknown
273
     */
274
    public function testParseUnknown()
275
    {
276
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
277
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
278
        $v = imagecreate(1, 1);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
279
        imagedestroy($v);
280
281
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
282
283
        $this->assertEquals('unknown', $o->type);
284
        $this->assertNull($o->value);
285
    }
286
287
    /**
288
     * @covers \Kint\Parser\Parser::parseArray
289
     * @covers \Kint\Parser\Parser::parseObject
290
     */
291
    public function testParseReferences()
292
    {
293
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
294
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
295
        $r = 1234;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $r. Configured minimum length is 3.

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.

Loading history...
296
        $v = array(&$r, 1234);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
297
298
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
299
300
        $this->assertEquals(true, $o->value->contents[0]->reference);
301
        $this->assertEquals(false, $o->value->contents[1]->reference);
302
303
        $v = new stdClass();
304
        $v->v1 = &$r;
305
        $v->v2 = 1234;
306
307
        $o = $p->parse($v, clone $b);
308
309
        $this->assertEquals(true, $o->value->contents[0]->reference);
310
        $this->assertEquals(false, $o->value->contents[1]->reference);
311
    }
312
313
    /**
314
     * @covers \Kint\Parser\Parser::parseArray
315
     * @covers \Kint\Parser\Parser::parseObject
316
     */
317
    public function testParseRecursion()
318
    {
319
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
320
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
321
        $v = array();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
322
        $v[] = &$v;
323
324
        $recursed = false;
325
326
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. Configured minimum length is 3.

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.

Loading history...
327
            array('array', 'object'),
328
            Parser::TRIGGER_RECURSION,
329
            function () use (&$recursed) {
330
                $recursed = true;
331
            }
332
        );
333
        $p->addPlugin($pl);
334
335
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
336
337
        $this->assertContains('recursion', $o->value->contents[0]->hints);
338
        $this->assertEquals(true, $recursed);
339
340
        $v = new stdClass();
341
        $v->v = $v;
342
343
        $recursed = false;
344
345
        $o = $p->parse($v, clone $b);
346
347
        $this->assertContains('recursion', $o->value->contents[0]->hints);
348
        $this->assertEquals(true, $recursed);
349
    }
350
351
    /**
352
     * @covers \Kint\Parser\Parser::parseDeep
353
     * @covers \Kint\Parser\Parser::parseArray
354
     * @covers \Kint\Parser\Parser::parseObject
355
     */
356
    public function testParseDepthLimit()
357
    {
358
        $p = new Parser(1);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
359
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
360
        $v = array(array(1234));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
361
362
        $limit = false;
363
364
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. Configured minimum length is 3.

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.

Loading history...
365
            array('array', 'object'),
366
            Parser::TRIGGER_DEPTH_LIMIT,
367
            function () use (&$limit) {
368
                $limit = true;
369
            }
370
        );
371
        $p->addPlugin($pl);
372
373
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
374
375
        $this->assertContains('depth_limit', $o->value->contents[0]->hints);
376
        $this->assertTrue($limit);
377
378
        $limit = false;
379
380
        $v = new stdClass();
381
        $v->v = 1234;
382
        $v = array($v);
383
384
        $o = $p->parse($v, clone $b);
385
386
        $this->assertContains('depth_limit', $o->value->contents[0]->hints);
387
        $this->assertTrue($limit);
388
389
        $limit = false;
390
391
        $o = $p->parseDeep($v, clone $b);
392
393
        $this->assertNotContains('depth_limit', $o->value->contents[0]->hints);
394
        $this->assertFalse($limit);
395
    }
396
397
    /**
398
     * @covers \Kint\Parser\Parser::parseArray
399
     * @covers \Kint\Parser\Parser::parseObject
400
     */
401
    public function testParseCastKeys()
402
    {
403
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
404
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
405
406
        // Object from array
407
        $v1 = (object) array('value');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v1. Configured minimum length is 3.

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.

Loading history...
408
        $o1 = $p->parse($v1, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o1. Configured minimum length is 3.

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.

Loading history...
409
410
        // Normal object
411
        $v2 = new stdClass();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v2. Configured minimum length is 3.

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.

Loading history...
412
        $v2->{0} = 'value';
413
        $o2 = $p->parse($v2, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o2. Configured minimum length is 3.

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.

Loading history...
414
415
        // Array from object
416
        $v3 = new stdClass();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v3. Configured minimum length is 3.

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.

Loading history...
417
        $v3->{0} = 'value';
418
        $v3 = (array) $v3;
419
        $o3 = $p->parse($v3, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o3. Configured minimum length is 3.

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.

Loading history...
420
421
        // Normal array
422
        $v4 = array('value');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v4. Configured minimum length is 3.

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.

Loading history...
423
        $o4 = $p->parse($v4, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o4. Configured minimum length is 3.

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.

Loading history...
424
425
        // Object with both
426
        $v5 = (object) array('value');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v5. Configured minimum length is 3.

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.

Loading history...
427
        $v5->{0} = 'value2';
428
        $o5 = $p->parse($v5, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o5. Configured minimum length is 3.

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.

Loading history...
429
430
        // Array with both
431
        $v6 = new stdClass();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v6. Configured minimum length is 3.

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.

Loading history...
432
        $v6->{0} = 'value';
433
        $v6 = (array) $v6;
434
        $v6['0'] = 'value2';
435
        $o6 = $p->parse($v6, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o6. Configured minimum length is 3.

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.

Loading history...
436
437
        if (version_compare(PHP_VERSION, '7.2') >= 0) {
438
            // Object from array
439
            $this->assertEquals(1, $o1->size);
440
            $this->assertEquals('value', $o1->value->contents[0]->value->contents);
441
            $this->assertEquals('$v->{\'0\'}', $o1->value->contents[0]->access_path);
442
            $this->assertTrue(isset($v1->{'0'}));
443
            $this->assertSame('0', $o1->value->contents[0]->name);
444
445
            // Normal object
446
            $this->assertEquals(1, $o2->size);
447
            $this->assertEquals('value', $o2->value->contents[0]->value->contents);
448
            $this->assertEquals('$v->{\'0\'}', $o2->value->contents[0]->access_path);
449
            $this->assertTrue(isset($v2->{'0'}));
450
            $this->assertSame('0', $o2->value->contents[0]->name);
451
452
            // Array from object
453
            $this->assertEquals(1, $o3->size);
454
            $this->assertEquals('value', $o3->value->contents[0]->value->contents);
455
            $this->assertEquals('$v[0]', $o3->value->contents[0]->access_path);
456
            $this->assertTrue(isset($v3['0']));
457
            $this->assertSame(0, $o3->value->contents[0]->name);
458
459
            // Normal array
460
            $this->assertEquals(1, $o4->size);
461
            $this->assertEquals('value', $o4->value->contents[0]->value->contents);
462
            $this->assertEquals('$v[0]', $o4->value->contents[0]->access_path);
463
            $this->assertTrue(isset($v4['0']));
464
            $this->assertSame(0, $o4->value->contents[0]->name);
465
466
            // Object with both
467
            $this->assertEquals(1, $o5->size);
468
            $this->assertEquals('value2', $o5->value->contents[0]->value->contents);
469
            $this->assertEquals('$v->{\'0\'}', $o5->value->contents[0]->access_path);
470
            $this->assertSame('0', $o5->value->contents[0]->name);
471
472
            // Array with both
473
            $this->assertEquals(1, $o6->size);
474
            $this->assertEquals('value2', $o6->value->contents[0]->value->contents);
475
            $this->assertEquals('$v[0]', $o6->value->contents[0]->access_path);
476
            $this->assertSame(0, $o6->value->contents[0]->name);
477
478
            // Object with both and weak equality (As of PHP 7.2)
479
            $v7 = (object) array('value');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v7. Configured minimum length is 3.

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.

Loading history...
480
            $v7->{'0'} = 'value2';
481
            $v7->{''} = 'value3';
482
            $o7 = $p->parse($v7, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o7. Configured minimum length is 3.

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.

Loading history...
483
484
            // Object with both and weak equality
485
            $this->assertEquals(2, $o7->size);
486 View Code Duplication
            foreach ($o7->value->contents as $o) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
487
                $this->assertContains($o->value->contents, array('value2', 'value3'));
488
489
                if ($o->value->contents === 'value2') {
490
                    $this->assertEquals('$v->{\'0\'}', $o->access_path);
491
                    $this->assertSame('0', $o->name);
492
                } elseif ($o->value->contents === 'value3') {
493
                    $this->assertEquals('$v->{\'\'}', $o->access_path);
494
                    $this->assertSame('', $o->name);
495
                }
496
            }
497
        } else {
498
            // Object from array
499
            $this->assertEquals(1, $o1->size);
500
            $this->assertEquals('value', $o1->value->contents[0]->value->contents);
501
            $this->assertEquals('array_values((array) $v)[0]', $o1->value->contents[0]->access_path);
502
            $this->assertFalse(isset($v1->{'0'}));
503
            $this->assertSame(0, $o1->value->contents[0]->name);
504
505
            // Normal object
506
            $this->assertEquals(1, $o2->size);
507
            $this->assertEquals('value', $o2->value->contents[0]->value->contents);
508
            $this->assertEquals('$v->{\'0\'}', $o2->value->contents[0]->access_path);
509
            $this->assertTrue(isset($v2->{'0'}));
510
            $this->assertSame('0', $o2->value->contents[0]->name);
511
512
            // Array from object
513
            $this->assertEquals(1, $o3->size);
514
            $this->assertEquals('value', $o3->value->contents[0]->value->contents);
515
            $this->assertEquals('array_values($v)[0]', $o3->value->contents[0]->access_path);
516
            $this->assertFalse(isset($v3['0']));
517
            $this->assertSame('0', $o3->value->contents[0]->name);
518
519
            // Normal array
520
            $this->assertEquals(1, $o4->size);
521
            $this->assertEquals('value', $o4->value->contents[0]->value->contents);
522
            $this->assertEquals('$v[0]', $o4->value->contents[0]->access_path);
523
            $this->assertTrue(isset($v4['0']));
524
            $this->assertSame(0, $o4->value->contents[0]->name);
525
526
            // Object with both
527
            $this->assertEquals(2, $o5->size);
528 View Code Duplication
            foreach ($o5->value->contents as $o) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
529
                $this->assertContains($o->value->contents, array('value', 'value2'));
530
531
                if ($o->value->contents === 'value') {
532
                    $this->assertEquals('array_values((array) $v)[0]', $o->access_path);
533
                    $this->assertSame(0, $o->name);
534
                } elseif ($o->value->contents === 'value2') {
535
                    $this->assertEquals('$v->{\'0\'}', $o->access_path);
536
                    $this->assertSame('0', $o->name);
537
                }
538
            }
539
540
            // Array with both
541
            $this->assertEquals(2, $o6->size);
542 View Code Duplication
            foreach ($o6->value->contents as $o) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
543
                $this->assertContains($o->value->contents, array('value', 'value2'));
544
545
                if ($o->value->contents === 'value') {
546
                    $this->assertEquals('array_values($v)[0]', $o->access_path);
547
                    $this->assertSame('0', $o->name);
548
                } elseif ($o->value->contents === 'value2') {
549
                    $this->assertEquals('$v[0]', $o->access_path);
550
                    $this->assertSame(0, $o->name);
551
                }
552
            }
553
        }
554
    }
555
556
    /**
557
     * @covers \Kint\Parser\Parser::parseObject
558
     * @covers \Kint\Parser\Parser::childHasPath
559
     */
560
    public function testParseAccessPathAvailability()
561
    {
562
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
563
        $v = new ChildTestClass();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
564
565
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
566
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
567
        $properties = array();
568
        foreach ($o->value->contents as $prop) {
569
            $properties[$prop->name] = $prop;
570
        }
571
        $this->assertEquals('$v->pub', $properties['pub']->access_path);
572
        $this->assertNull($properties['pro']->access_path);
573
        $this->assertNull($properties['pri']->access_path);
574
575
        $p = new Parser(false, 'Kint\\Test\\Fixtures\\ChildTestClass');
576
        $o = $p->parse($v, clone $b);
577
        $properties = array();
578
        foreach ($o->value->contents as $prop) {
579
            $properties[$prop->name] = $prop;
580
        }
581
        $this->assertEquals('$v->pub', $properties['pub']->access_path);
582
        $this->assertEquals('$v->pro', $properties['pro']->access_path);
583
        $this->assertNull($properties['pri']->access_path);
584
585
        $p = new Parser(false, 'Kint\\Test\\Fixtures\\TestClass');
586
        $o = $p->parse($v, clone $b);
587
        $properties = array();
588
        foreach ($o->value->contents as $prop) {
589
            $properties[$prop->name] = $prop;
590
        }
591
        $this->assertEquals('$v->pub', $properties['pub']->access_path);
592
        $this->assertEquals('$v->pro', $properties['pro']->access_path);
593
        $this->assertEquals('$v->pri', $properties['pri']->access_path);
594
    }
595
596
    /**
597
     * @covers \Kint\Parser\Parser::applyPlugins
598
     * @covers \Kint\Parser\Parser::addPlugin
599
     * @covers \Kint\Parser\Parser::clearPlugins
600
     */
601
    public function testPlugins()
602
    {
603
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
604
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
605
        $v = 1234;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
606
607
        $o = $p->parse($v, clone $b);
608
609
        $this->assertObjectNotHasAttribute('testPluginCorrectlyActivated', $o);
610
611
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. Configured minimum length is 3.

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.

Loading history...
612
            array('integer'),
613
            Parser::TRIGGER_SUCCESS,
614
            function (&$var, &$o) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
615
                $o->testPluginCorrectlyActivated = true;
616
            }
617
        );
618
        $p->addPlugin($pl);
619
620
        $o = $p->parse($v, clone $b);
621
622
        $this->assertObjectHasAttribute('testPluginCorrectlyActivated', $o);
623
624
        $p->clearPlugins();
625
626
        $o = $p->parse($v, clone $b);
627
628
        $this->assertObjectNotHasAttribute('testPluginCorrectlyActivated', $o);
629
630
        $pl = new ProxyPlugin(
631
            array(),
632
            Parser::TRIGGER_SUCCESS,
633
            function () {}
634
        );
635
        $this->assertFalse($p->addPlugin($pl));
636
637
        $pl = new ProxyPlugin(
638
            array('integer'),
639
            Parser::TRIGGER_NONE,
640
            function () {}
641
        );
642
        $this->assertFalse($p->addPlugin($pl));
643
    }
644
645
    /**
646
     * @covers \Kint\Parser\Parser::applyPlugins
647
     * @covers \Kint\Parser\Parser::addPlugin
648
     */
649
    public function testTriggers()
650
    {
651
        $p = new Parser(1);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
652
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
653
        $v = array(1234, array(1234));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
654
        $v[] = &$v;
655
656
        $triggers = array();
657
658
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. Configured minimum length is 3.

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.

Loading history...
659
            array('integer', 'array'),
660
            Parser::TRIGGER_BEGIN | Parser::TRIGGER_COMPLETE,
661
            function (&$var, &$o, $trig) use (&$triggers) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
662
                $triggers[] = $trig;
663
            }
664
        );
665
        $p->addPlugin($pl);
666
667
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Unused Code introduced by
$o is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
668
669
        $this->assertEquals(
670
            array(
671
                Parser::TRIGGER_BEGIN,
672
                Parser::TRIGGER_BEGIN,
673
                Parser::TRIGGER_SUCCESS,
674
                Parser::TRIGGER_BEGIN,
675
                Parser::TRIGGER_DEPTH_LIMIT,
676
                Parser::TRIGGER_BEGIN,
677
                Parser::TRIGGER_RECURSION,
678
                Parser::TRIGGER_SUCCESS,
679
            ),
680
            $triggers
681
        );
682
    }
683
684
    /**
685
     * @covers \Kint\Parser\Parser::parse
686
     * @covers \Kint\Parser\Parser::applyPlugins
687
     * @covers \Kint\Parser\Parser::haltParse
688
     */
689
    public function testHaltParse()
690
    {
691
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
692
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
693
        $t = clone $b;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $t. Configured minimum length is 3.

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.

Loading history...
694
        $t->type = 'integer';
695
        $v = 1234;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
696
697
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. Configured minimum length is 3.

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.

Loading history...
698
            array('integer'),
699
            Parser::TRIGGER_BEGIN,
700
            function (&$var, &$o, $trig, $parser) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
701
                $parser->haltParse();
702
            }
703
        );
704
        $p->addPlugin($pl);
705
706
        $o = $p->parse($v, $t);
707
708
        $this->assertSame($t, $o);
709
710
        $p->clearPlugins();
711
712
        $pl = new ProxyPlugin(
713
            array('integer'),
714
            Parser::TRIGGER_SUCCESS,
715
            function (&$var, &$o, $trig, $parser) {
716
                $parser->haltParse();
717
            }
718
        );
719
        $p->addPlugin($pl);
720
721
        $pl = new ProxyPlugin(
722
            array('integer'),
723
            Parser::TRIGGER_SUCCESS,
724
            function (&$var, &$o) {
725
                $o->testPluginCorrectlyActivated = true;
726
            }
727
        );
728
        $p->addPlugin($pl);
729
730
        $o = $p->parse($v, clone $b);
731
732
        $this->assertObjectNotHasAttribute('testPluginCorrectlyActivated', $o);
733
    }
734
735
    /**
736
     * @expectedException \PHPUnit_Framework_Error_Warning
737
     * @covers \Kint\Parser\Parser::applyPlugins
738
     */
739
    public function testPluginExceptionBecomesWarning()
740
    {
741
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
742
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
743
        $t = clone $b;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $t. Configured minimum length is 3.

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.

Loading history...
744
        $t->type = 'integer';
745
        $v = 1234;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
746
747
        $message = __FUNCTION__;
748
749
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. Configured minimum length is 3.

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.

Loading history...
750
            array('integer'),
751
            Parser::TRIGGER_BEGIN,
752
            function (&$var, &$o, $trig, $parser) use ($message) {
0 ignored issues
show
Unused Code introduced by
The parameter $var is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $o is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $trig is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
753
                throw new Exception($message);
754
            }
755
        );
756
        $p->addPlugin($pl);
757
758
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Unused Code introduced by
$o is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
759
    }
760
761
    public function childHasPathProvider()
762
    {
763
        $data = array();
764
765
        $expected = array(
766
            'public parser' => array(
767
                new Parser(),
768
                array(
769
                    'props' => array('$v', false, true, false, false),
770
                    'statics' => array('$v', true, true, false, false),
771
                    'props without path' => array(null, false, false, false, false),
772
                    'statics without path' => array(null, true, true, false, false),
773
                ),
774
            ),
775
            'protected parser' => array(
776
                new Parser(false, 'Kint\\Test\\Fixtures\\ChildTestClass'),
777
                array(
778
                    'props' => array('$v', false, true, true, false),
779
                    'statics' => array('$v', true, true, true, false),
780
                    'props without path' => array(null, false, false, false, false),
781
                    'statics without path' => array(null, true, true, true, false),
782
                ),
783
            ),
784
            'private parser' => array(
785
                new Parser(false, 'Kint\\Test\\Fixtures\\TestClass'),
786
                array(
787
                    'props' => array('$v', false, true, true, true),
788
                    'statics' => array('$v', true, true, true, true),
789
                    'props without path' => array(null, false, false, false, false),
790
                    'statics without path' => array(null, true, true, true, true),
791
                ),
792
            ),
793
        );
794
795
        foreach ($expected as $parser_name => $params) {
0 ignored issues
show
Coding Style introduced by
$parser_name does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
796
            list($parser, $opts) = $params;
797
798
            foreach ($opts as $name => $set) {
799
                list($path, $static, $pub, $pro, $pri) = $set;
800
801
                $visibilities = array(
802
                    BasicObject::ACCESS_PUBLIC => $pub,
803
                    BasicObject::ACCESS_PROTECTED => $pro,
804
                    BasicObject::ACCESS_PRIVATE => $pri,
805
                );
806
807
                foreach ($visibilities as $visibility => $expect) {
808
                    $parent = BasicObject::blank();
809
                    $parent = $parent->transplant(new InstanceObject());
810
                    $parent->classname = 'Kint\\Test\\Fixtures\\ChildTestClass';
0 ignored issues
show
Bug introduced by
The property classname does not seem to exist in Kint\Object\BasicObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
811
                    $parent->type = 'object';
812
813
                    $r = new Representation('Contents');
814
                    $parent->addRepresentation($r);
815
816
                    $prop = BasicObject::blank();
817
                    $r->contents = array($prop);
818
                    $prop->owner_class = 'Kint\\Test\\Fixtures\\TestClass';
819
820
                    $parent->access_path = $path;
821
                    $prop->static = $static;
822
                    $prop->access = $visibility;
823
824
                    $data[$parser_name.', '.$visibility.' '.$name] = array($parser, $parent, $prop, $expect);
0 ignored issues
show
Coding Style introduced by
$parser_name does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
825
                }
826
            }
827
        }
828
829
        return $data;
830
    }
831
832
    /**
833
     * @dataProvider childHasPathProvider
834
     * @covers \Kint\Parser\Parser::childHasPath
835
     */
836
    public function testChildHasPath($parser, $parent, $child, $expected)
837
    {
838
        $this->assertEquals($expected, $parser->childHasPath($parent, $child));
839
    }
840
841
    /**
842
     * @covers \Kint\Parser\Parser::getCleanArray
843
     */
844
    public function testGetCleanArray()
845
    {
846
        $p = new Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

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.

Loading history...
847
        $b = BasicObject::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

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.

Loading history...
848
        $v = array(1234);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

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.

Loading history...
849
850
        $arrays = array();
851
852
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. Configured minimum length is 3.

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.

Loading history...
853
            array('array'),
854
            Parser::TRIGGER_SUCCESS,
855
            function (&$var, &$o, $trig, $parser) use (&$arrays) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

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.

Loading history...
856
                $clean = $parser->getCleanArray($var);
857
858
                // This here is exactly why you should never alter input
859
                // variables in plugins and always use getCleanArray
860
                $var[] = 4321;
861
                $clean[] = 8765;
862
863
                $arrays = array(
864
                    'var' => $var,
865
                    'clean' => $clean,
866
                );
867
            }
868
        );
869
        $p->addPlugin($pl);
870
871
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Unused Code introduced by
$o is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
872
873
        $this->assertEquals(array(1234, 4321), $v);
874
        $this->assertEquals(array(1234, 8765), $arrays['clean']);
875
        $this->assertEquals(count($v) + 1, count($arrays['var']));
876
    }
877
}
878