GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b7415a...e1a3c3 )
by Juan
01:35
created

testUnserializeUndeclaredPropertySet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Zumba\JsonSerializer\Test;
4
5
use Zumba\JsonSerializer\JsonSerializer;
6
use stdClass;
7
use SuperClosure\Serializer as ClosureSerializer;
8
9
class JsonSerializerTest extends \PHPUnit_Framework_TestCase
10
{
11
12
    /**
13
     * Serializer instance
14
     *
15
     * @var JsonSerializer
16
     */
17
    protected $serializer;
18
19
    /**
20
     * Test case setup
21
     *
22
     * @return void
23
     */
24
    public function setUp()
25
    {
26
        parent::setUp();
27
        $customObjectSerializerMap['Zumba\\JsonSerializer\\Test\\SupportClasses\\MyType'] = new \Zumba\JsonSerializer\Test\SupportClasses\MyTypeSerializer();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$customObjectSerializerMap was never initialized. Although not strictly required by PHP, it is generally a good practice to add $customObjectSerializerMap = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
28
        $this->serializer = new JsonSerializer(null, $customObjectSerializerMap);
29
    }
30
31
    /**
32
     * Test serialization of scalar values
33
     *
34
     * @dataProvider scalarData
35
     * @param mixed $scalar
36
     * @param string $jsoned
37
     * @return void
38
     */
39
    public function testSerializeScalar($scalar, $jsoned)
40
    {
41
        $this->assertSame($jsoned, $this->serializer->serialize($scalar));
42
    }
43
44
    /**
45
     * Test serialization of float values with locale
46
     *
47
     * @return void
48
     */
49
    public function testSerializeFloatLocalized()
50
    {
51
        $possibleLocales = ['fr_FR', 'fr_FR.utf8', 'fr', 'fra', 'French'];
52
        $originalLocale = setlocale(LC_NUMERIC, 0);
53
        if (!setlocale(LC_NUMERIC, $possibleLocales)) {
54
            $this->markTestSkipped('Unable to set an i18n locale.');
55
        }
56
57
        $data = [1.0, 1.1, 0.00000000001, 1.999999999999, 223423.123456789, 1e5, 1e11];
58
        $expected = version_compare(PHP_VERSION, '7.1', '>=') ?
59
            '[1.0,1.1,1.0e-11,1.999999999999,223423.123456789,100000.0,100000000000.0]' :
60
            '[1.0,1.1,1.0e-11,1.999999999999,223423.12345679,100000.0,100000000000.0]';
61
        $this->assertSame($expected, $this->serializer->serialize($data));
62
63
        setlocale(LC_NUMERIC, $originalLocale);
64
    }
65
    /**
66
     * Test unserialization of scalar values
67
     *
68
     * @dataProvider scalarData
69
     * @param mixed $scalar
70
     * @param string $jsoned
71
     * @return void
72
     */
73
    public function testUnserializeScalar($scalar, $jsoned)
74
    {
75
        $this->assertSame($scalar, $this->serializer->unserialize($jsoned));
76
    }
77
78
    /**
79
     * List of scalar data
80
     *
81
     * @return array
82
     */
83
    public function scalarData()
84
    {
85
        return array(
86
            array('testing', '"testing"'),
87
            array(123, '123'),
88
            array(0, '0'),
89
            array(0.0, '0.0'),
90
            array(17.0, '17.0'),
91
            array(17e1, '170.0'),
92
            array(17.2, '17.2'),
93
            array(true, 'true'),
94
            array(false, 'false'),
95
            array(null, 'null'),
96
            // Non UTF8
97
            array('ßåö', '"ßåö"')
98
        );
99
    }
100
101
    /**
102
     * Test the serialization of resources
103
     *
104
     * @return void
105
     */
106
    public function testSerializeResource()
107
    {
108
        $this->setExpectedException('Zumba\JsonSerializer\Exception\JsonSerializerException');
109
        $this->serializer->serialize(fopen(__FILE__, 'r'));
110
    }
111
112
    /**
113
     * Test the serialization of closures when not providing closure serializer
114
     *
115
     * @return void
116
     */
117
    public function testSerializeClosureWithoutSerializer()
118
    {
119
        $this->setExpectedException('Zumba\JsonSerializer\Exception\JsonSerializerException');
120
        $this->serializer->serialize(array('func' => function () {
121
            echo 'whoops';
122
        }));
123
    }
124
125
    /**
126
     * Test serialization of array without objects
127
     *
128
     * @dataProvider arrayNoObjectData
129
     * @param array $array
130
     * @param string $jsoned
131
     * @return void
132
     */
133
    public function testSerializeArrayNoObject($array, $jsoned)
134
    {
135
        $this->assertSame($jsoned, $this->serializer->serialize($array));
136
    }
137
138
    /**
139
     * Test unserialization of array without objects
140
     *
141
     * @dataProvider arrayNoObjectData
142
     * @param array $array
143
     * @param string $jsoned
144
     * @return void
145
     */
146
    public function testUnserializeArrayNoObject($array, $jsoned)
147
    {
148
        $this->assertSame($array, $this->serializer->unserialize($jsoned));
149
    }
150
151
    /**
152
     * List of array data
153
     *
154
     * @return array
155
     */
156
    public function arrayNoObjectData()
157
    {
158
        return array(
159
            array(array(1, 2, 3), '[1,2,3]'),
160
            array(array(1, 'abc', false), '[1,"abc",false]'),
161
            array(array('a' => 1, 'b' => 2, 'c' => 3), '{"a":1,"b":2,"c":3}'),
162
            array(array('integer' => 1, 'string' => 'abc', 'bool' => false), '{"integer":1,"string":"abc","bool":false}'),
163
            array(array(1, array('nested')), '[1,["nested"]]'),
164
            array(array('integer' => 1, 'array' => array('nested')), '{"integer":1,"array":["nested"]}'),
165
            array(array('integer' => 1, 'array' => array('nested' => 'object')), '{"integer":1,"array":{"nested":"object"}}'),
166
            array(array(1.0, 2, 3e1), '[1.0,2,30.0]'),
167
        );
168
    }
169
170
    /**
171
     * Test serialization of objects
172
     *
173
     * @return void
174
     */
175
    public function testSerializeObject()
176
    {
177
        $obj = new stdClass();
178
        $this->assertSame('{"@type":"stdClass"}', $this->serializer->serialize($obj));
179
180
        $obj = $empty = new SupportClasses\EmptyClass();
181
        $this->assertSame('{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\EmptyClass"}', $this->serializer->serialize($obj));
182
183
        $obj = new SupportClasses\AllVisibilities();
184
        $expected = '{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\AllVisibilities","pub":"this is public","prot":"protected","priv":"dont tell anyone"}';
185
        $this->assertSame($expected, $this->serializer->serialize($obj));
186
187
        $obj->pub = 'new value';
188
        $expected = '{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\AllVisibilities","pub":"new value","prot":"protected","priv":"dont tell anyone"}';
189
        $this->assertSame($expected, $this->serializer->serialize($obj));
190
191
        $obj->pub = $empty;
0 ignored issues
show
Documentation Bug introduced by
It seems like $empty of type object<Zumba\JsonSeriali...portClasses\EmptyClass> is incompatible with the declared type string of property $pub.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
192
        $expected = '{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\AllVisibilities","pub":{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\EmptyClass"},"prot":"protected","priv":"dont tell anyone"}';
193
        $this->assertSame($expected, $this->serializer->serialize($obj));
194
195
        $array = array('instance' => $empty);
196
        $expected = '{"instance":{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\EmptyClass"}}';
197
        $this->assertSame($expected, $this->serializer->serialize($array));
198
199
        $obj = new stdClass();
200
        $obj->total = 10.0;
201
        $obj->discount = 0.0;
202
        $expected = '{"@type":"stdClass","total":10.0,"discount":0.0}';
203
        $this->assertSame($expected, $this->serializer->serialize($obj));
204
    }
205
206
    /**
207
     * Test unserialization of objects
208
     *
209
     * @return void
210
     */
211
    public function testUnserializeObjects()
212
    {
213
        $serialized = '{"@type":"stdClass"}';
214
        $obj = $this->serializer->unserialize($serialized);
215
        $this->assertInstanceOf('stdClass', $obj);
216
217
        $serialized = '{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\EmptyClass"}';
218
        $obj = $this->serializer->unserialize($serialized);
219
        $this->assertInstanceOf('Zumba\JsonSerializer\Test\SupportClasses\EmptyClass', $obj);
220
221
        $serialized = '{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\AllVisibilities","pub":{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\EmptyClass"},"prot":"protected","priv":"dont tell anyone"}';
222
        $obj = $this->serializer->unserialize($serialized);
223
        $this->assertInstanceOf('Zumba\JsonSerializer\Test\SupportClasses\AllVisibilities', $obj);
224
        $this->assertInstanceOf('Zumba\JsonSerializer\Test\SupportClasses\EmptyClass', $obj->pub);
225
        $this->assertAttributeSame('protected', 'prot', $obj);
226
        $this->assertAttributeSame('dont tell anyone', 'priv', $obj);
227
228
        $serialized = '{"instance":{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\EmptyClass"}}';
229
        $array = $this->serializer->unserialize($serialized);
230
        $this->assertTrue(is_array($array));
231
        $this->assertInstanceOf('Zumba\JsonSerializer\Test\SupportClasses\EmptyClass', $array['instance']);
232
    }
233
234
235
    /**
236
     * Test serialization of objects using the custom serializers
237
     *
238
     * @return void
239
     */
240
    public function testCustomObjectSerializer()
241
    {
242
        $obj = new SupportClasses\MyType();
243
        $obj->field1 = 'x';
244
        $obj->field2 = 'y';
245
        $this->assertSame('{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\MyType","fields":"x y"}', $this->serializer->serialize($obj));
246
    }
247
248
    /**
249
     * Test unserialization of objects using the custom serializers
250
     *
251
     * @return void
252
     */
253
    public function testCustomObjectsUnserializer()
254
    {
255
        $serialized = '{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\MyType","fields":"x y"}';
256
        $obj = $this->serializer->unserialize($serialized);
257
        $this->assertInstanceOf('Zumba\JsonSerializer\Test\SupportClasses\MyType', $obj);
258
        $this->assertAttributeSame('x', 'field1', $obj);
259
        $this->assertAttributeSame('y', 'field2', $obj);
260
    }
261
262
    /**
263
     * Test magic serialization methods
264
     *
265
     * @return void
266
     */
267
    public function testSerializationMagicMethods()
268
    {
269
        $obj = new SupportClasses\MagicClass();
270
        $serialized = '{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\MagicClass","show":true}';
271
        $this->assertSame($serialized, $this->serializer->serialize($obj));
272
        $this->assertFalse($obj->woke);
273
274
        $obj = $this->serializer->unserialize($serialized);
275
        $this->assertTrue($obj->woke);
276
    }
277
278
    /**
279
     * Test serialization of DateTime classes
280
     *
281
     * Some interal classes, such as DateTime, cannot be initialized with
282
     * ReflectionClass::newInstanceWithoutConstructor()
283
     *
284
     * @return void
285
     */
286
    public function testSerializationOfDateTime()
287
    {
288
        $date = new \DateTime('2014-06-15 12:00:00', new \DateTimeZone('UTC'));
289
        $obj = $this->serializer->unserialize($this->serializer->serialize($date));
290
        $this->assertSame($date->getTimestamp(), $obj->getTimestamp());
291
    }
292
293
    /**
294
     * Test the serialization of closures providing closure serializer
295
     *
296
     * @return void
297
     */
298
    public function testSerializationOfClosure()
299
    {
300
        if (!class_exists('SuperClosure\Serializer')) {
301
            $this->markTestSkipped('SuperClosure is not installed.');
302
        }
303
304
        $closureSerializer = new ClosureSerializer();
305
        $serializer = new JsonSerializer($closureSerializer);
306
        $serialized = $serializer->serialize(array(
307
            'func' => function () {
308
                return 'it works';
309
            },
310
            'nice' => true
311
        ));
312
313
        $unserialized = $serializer->unserialize($serialized);
314
        $this->assertTrue(is_array($unserialized));
315
        $this->assertTrue($unserialized['nice']);
316
        $this->assertInstanceOf('Closure', $unserialized['func']);
317
        $this->assertSame('it works', $unserialized['func']());
318
    }
319
320
    /**
321
     * Test the unserialization of closures without providing closure serializer
322
     *
323
     * @return void
324
     */
325
    public function testUnserializeOfClosureWithoutSerializer()
326
    {
327
        if (!class_exists('SuperClosure\Serializer')) {
328
            $this->markTestSkipped('SuperClosure is not installed.');
329
        }
330
331
        $closureSerializer = new ClosureSerializer();
332
        $serializer = new JsonSerializer($closureSerializer);
333
        $serialized = $serializer->serialize(array(
334
            'func' => function () {
335
                return 'it works';
336
            },
337
            'nice' => true
338
        ));
339
340
        $this->setExpectedException('Zumba\JsonSerializer\Exception\JsonSerializerException');
341
        $this->serializer->unserialize($serialized);
342
    }
343
344
    /**
345
     * Test unserialize of unknown class
346
     *
347
     * @return void
348
     */
349
    public function testUnserializeUnknownClass()
350
    {
351
        $this->setExpectedException('Zumba\JsonSerializer\Exception\JsonSerializerException');
352
        $serialized = '{"@type":"UnknownClass"}';
353
        $this->serializer->unserialize($serialized);
354
    }
355
356
    /**
357
     * Test serialization of undeclared properties
358
     *
359
     * @return void
360
     */
361
    public function testSerializationUndeclaredProperties()
362
    {
363
        $obj = new stdClass();
364
        $obj->param1 = true;
365
        $obj->param2 = 'store me, please';
366
        $serialized = '{"@type":"stdClass","param1":true,"param2":"store me, please"}';
367
        $this->assertSame($serialized, $this->serializer->serialize($obj));
368
369
        $obj2 = $this->serializer->unserialize($serialized);
370
        $this->assertInstanceOf('stdClass', $obj2);
371
        $this->assertTrue($obj2->param1);
372
        $this->assertSame('store me, please', $obj2->param2);
373
374
        $serialized = '{"@type":"stdClass","sub":{"@type":"stdClass","key":"value"}}';
375
        $obj = $this->serializer->unserialize($serialized);
376
        $this->assertInstanceOf('stdClass', $obj->sub);
377
        $this->assertSame('value', $obj->sub->key);
378
    }
379
380
    /**
381
     * Test undeclared properties setter (valid)
382
     *
383
     * @return void
384
     */
385
    public function testSetUnserializeUndeclaredPropertyModeValid() {
386
        $value = $this->serializer->setUnserializeUndeclaredPropertyMode(JsonSerializer::UNDECLARED_PROPERTY_MODE_SET);
387
        $this->assertSame($value, $this->serializer);
388
    }
389
390
    /**
391
     * Test undeclared properties setter (invalid)
392
     *
393
     * @return void
394
     */
395
    public function testSetUnserializeUndeclaredPropertyModeInvalid() {
396
        $this->setExpectedException('InvalidArgumentException');
397
        $value = $this->serializer->setUnserializeUndeclaredPropertyMode('bad value');
0 ignored issues
show
Unused Code introduced by
$value 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...
398
    }
399
400
    /**
401
     * Test unserialization of undeclared properties in SET mode
402
     *
403
     * @return void
404
     */
405
    public function testUnserializeUndeclaredPropertySet() {
406
        $this->serializer->setUnserializeUndeclaredPropertyMode(JsonSerializer::UNDECLARED_PROPERTY_MODE_SET);
407
408
        $serialized = '{"@type":"stdClass","sub":{"@type":"stdClass","key":"value"}}';
409
        $obj = $this->serializer->unserialize($serialized);
410
        $this->assertInstanceOf('stdClass', $obj->sub);
411
        $this->assertSame('value', $obj->sub->key);
412
    }
413
414
    /**
415
     * Test unserialization of undeclared properties in IGNORE mode
416
     *
417
     * @return void
418
     */
419
    public function testUnserializeUndeclaredPropertyIgnore() {
420
        $this->serializer->setUnserializeUndeclaredPropertyMode(JsonSerializer::UNDECLARED_PROPERTY_MODE_IGNORE);
421
422
        $serialized = '{"@type":"stdClass","sub":{"@type":"stdClass","key":"value"}}';
423
        $obj = $this->serializer->unserialize($serialized);
424
        $this->assertFalse(isset($obj->sub));
425
    }
426
427
    /**
428
     * Test unserialization of undeclared properties in EXCEPTION mode
429
     *
430
     * @return void
431
     */
432
    public function testUnserializeUndeclaredPropertyException() {
433
        $this->serializer->setUnserializeUndeclaredPropertyMode(JsonSerializer::UNDECLARED_PROPERTY_MODE_EXCEPTION);
434
435
        $this->setExpectedException('Zumba\Exception\JsonSerializerException');
436
        $serialized = '{"@type":"stdClass","sub":{"@type":"stdClass","key":"value"}}';
437
        $obj = $this->serializer->unserialize($serialized);
0 ignored issues
show
Unused Code introduced by
$obj 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...
438
    }
439
440
    /**
441
     * Test serialize with recursion
442
     *
443
     * @return void
444
     */
445
    public function testSerializeRecursion()
446
    {
447
        $c1 = new stdClass();
448
        $c1->c2 = new stdClass();
449
        $c1->c2->c3 = new stdClass();
450
        $c1->c2->c3->c1 = $c1;
451
        $c1->something = 'ok';
452
        $c1->c2->c3->ok = true;
453
454
        $expected = '{"@type":"stdClass","c2":{"@type":"stdClass","c3":{"@type":"stdClass","c1":{"@type":"@0"},"ok":true}},"something":"ok"}';
455
        $this->assertSame($expected, $this->serializer->serialize($c1));
456
457
        $c1 = new stdClass();
458
        $c1->mirror = $c1;
459
        $expected = '{"@type":"stdClass","mirror":{"@type":"@0"}}';
460
        $this->assertSame($expected, $this->serializer->serialize($c1));
461
    }
462
463
    /**
464
     * Test unserialize with recursion
465
     *
466
     * @return void
467
     */
468
    public function testUnserializeRecursion()
469
    {
470
        $serialized = '{"@type":"stdClass","c2":{"@type":"stdClass","c3":{"@type":"stdClass","c1":{"@type":"@0"},"ok":true}},"something":"ok"}';
471
        $obj = $this->serializer->unserialize($serialized);
472
        $this->assertTrue($obj->c2->c3->ok);
473
        $this->assertSame($obj, $obj->c2->c3->c1);
474
        $this->assertNotSame($obj, $obj->c2);
475
476
        $serialized = '{"@type":"stdClass","c2":{"@type":"stdClass","c3":{"@type":"stdClass","c1":{"@type":"@0"},"c2":{"@type":"@1"},"c3":{"@type":"@2"}},"c3_copy":{"@type":"@2"}}}';
477
        $obj = $this->serializer->unserialize($serialized);
478
        $this->assertSame($obj, $obj->c2->c3->c1);
479
        $this->assertSame($obj->c2, $obj->c2->c3->c2);
480
        $this->assertSame($obj->c2->c3, $obj->c2->c3->c3);
481
        $this->assertSame($obj->c2->c3_copy, $obj->c2->c3);
482
    }
483
484
    /**
485
     * Test unserialize with bad JSON
486
     *
487
     * @return void
488
     */
489
    public function testUnserializeBadJSON()
490
    {
491
        $this->setExpectedException('Zumba\Exception\JsonSerializerException');
492
        $this->serializer->unserialize('[this is not a valid json!}');
493
    }
494
495
    /**
496
     * The test attempts to serialize an array containing a NAN
497
     */
498
    public function testSerializeInvalidData()
499
    {
500
        if (PHP_VERSION_ID < 50500) {
501
            $this->markTestSkipped('PHP 5.4 raises a warning when encoding NAN, which fails the test.');
502
        }
503
504
        $this->setExpectedException('Zumba\Exception\JsonSerializerException');
505
        $this->serializer->serialize(array(NAN));
506
    }
507
508
    /**
509
     * @return void
510
     */
511
    public function testSerializeBinaryStringScalar()
512
    {
513
        $data = '';
514
        for ($i = 0; $i <= 255; $i++) {
515
            $data .= chr($i);
516
        }
517
518
        $unserialized = $this->serializer->unserialize($this->serializer->serialize($data));
519
        $this->assertSame($data, $unserialized);
520
    }
521
522
    /**
523
     * @return void
524
     */
525
    public function testSerializeArrayWithBinaryStringsAsValues()
526
    {
527
        $data = '';
528
        for ($i = 0; $i <= 255; $i++) {
529
            $data .= chr($i);
530
        }
531
532
        $data = [$data, "$data 1", "$data 2"];
533
        $unserialized = $this->serializer->unserialize($this->serializer->serialize($data));
534
        $this->assertSame($data, $unserialized);
535
    }
536
537
    /**
538
     * Starting from 1 and not from 0 because php cannot handle the nil character (\u0000) in json keys as per:
539
     * https://github.com/remicollet/pecl-json-c/issues/7
540
     * https://github.com/json-c/json-c/issues/108
541
     *
542
     * @return void
543
     */
544
    public function testSerializeArrayWithBinaryStringsAsKeys()
545
    {
546
        $data = '';
547
        for ($i = 1; $i <= 255; $i++) {
548
            $data .= chr($i);
549
        }
550
551
        $data = [$data => $data, "$data 1" => 'something'];
552
        $unserialized = $this->serializer->unserialize($this->serializer->serialize($data));
553
        $this->assertSame($data, $unserialized);
554
    }
555
556
    /**
557
     * @return void
558
     */
559
    public function testSerializeObjectWithBinaryStrings()
560
    {
561
        $data = '';
562
        for ($i = 0; $i <= 255; $i++) {
563
            $data .= chr($i);
564
        }
565
566
        $obj = new \stdClass();
567
        $obj->string = $data;
568
        $unserialized = $this->serializer->unserialize($this->serializer->serialize($obj));
569
        $this->assertInstanceOf('stdClass', $obj);
570
        $this->assertSame($obj->string, $unserialized->string);
571
    }
572
573
    /*
574
     * Test namespace change (backward compatibility)
575
     *
576
     * @return void
577
     * @deprecated
578
     */
579
    public function testNamespaceRename()
580
    {
581
        $serializer = new \Zumba\Util\JsonSerializer();
0 ignored issues
show
Unused Code introduced by
$serializer 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...
Deprecated Code introduced by
The class Zumba\Util\JsonSerializer has been deprecated with message: Will be removed on the 3.0.0. Use Zumba\JsonSerializer\JsonSerializer instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
582
583
        $f = fopen(__FILE__, 'r');
584
        $this->setExpectedException('Zumba\Exception\JsonSerializerException');
585
        $this->serializer->serialize($f);
586
    }
587
588
    /**
589
     * Test serialization of SplDoubleLinkedList
590
     *
591
     * @return void
592
     */
593
    public function testSerializationOfSplDoublyLinkedList()
594
    {
595
        $list = new \SplDoublyLinkedList();
596
        $list->push('fizz');
597
        $list->push(42);
598
        $unserialized = $this->serializer->unserialize($this->serializer->serialize($list));
599
        $this->assertTrue($list->serialize() === $unserialized->serialize());
600
    }
601
}
602