|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespaceSymfony\Component\Cache\Tests\Traits; |
| 13 | + |
| 14 | +usePHPUnit\Framework\TestCase; |
| 15 | +useSymfony\Component\Cache\Traits\SerializingTrait; |
| 16 | + |
| 17 | +class SerializingTraitTestextends TestCase |
| 18 | +{ |
| 19 | +use SerializingTrait; |
| 20 | + |
| 21 | +publicfunctiontestSerialize() |
| 22 | + { |
| 23 | +$values =array( |
| 24 | +'a' =>123, |
| 25 | +'b' =>function () {}, |
| 26 | + ); |
| 27 | + |
| 28 | +$expected =array('a' =>\function_exists('igbinary_serialize') ?igbinary_serialize(123) :serialize(123)); |
| 29 | +$this->assertSame($expected,$this->serializeValues($values,$failed)); |
| 30 | +$this->assertSame(array('b'),$failed); |
| 31 | + } |
| 32 | + |
| 33 | +publicfunctiontestNativeUnserialize() |
| 34 | + { |
| 35 | +$this->assertNull($this->unserializeValue(serialize(null))); |
| 36 | +$this->assertFalse($this->unserializeValue(serialize(false))); |
| 37 | +$this->assertSame('',$this->unserializeValue(serialize(''))); |
| 38 | +$this->assertSame(0,$this->unserializeValue(serialize(0))); |
| 39 | + } |
| 40 | + |
| 41 | +/** |
| 42 | + * @requires extension igbinary |
| 43 | + */ |
| 44 | +publicfunctiontestIgbinaryUnserialize() |
| 45 | + { |
| 46 | +$this->assertNull($this->unserializeValue(igbinary_serialize(null))); |
| 47 | +$this->assertFalse($this->unserializeValue(igbinary_serialize(false))); |
| 48 | +$this->assertSame('',$this->unserializeValue(igbinary_serialize(''))); |
| 49 | +$this->assertSame(0,$this->unserializeValue(igbinary_serialize(0))); |
| 50 | + } |
| 51 | + |
| 52 | +/** |
| 53 | + * @expectedException \DomainException |
| 54 | + * @expectedExceptionMessage Class not found: NotExistingClass |
| 55 | + */ |
| 56 | +publicfunctiontestNativeUnserializeNotFoundClass() |
| 57 | + { |
| 58 | +$this->unserializeValue('O:16:"NotExistingClass":0:{}'); |
| 59 | + } |
| 60 | + |
| 61 | +/** |
| 62 | + * @requires extension igbinary |
| 63 | + * @expectedException \DomainException |
| 64 | + * @expectedExceptionMessage Class not found: NotExistingClass |
| 65 | + */ |
| 66 | +publicfunctiontestIgbinaryUnserializeNotFoundClass() |
| 67 | + { |
| 68 | +$this->unserializeValue(rawurldecode('%00%00%00%02%17%10NotExistingClass%14%00')); |
| 69 | + } |
| 70 | + |
| 71 | +/** |
| 72 | + * @expectedException \DomainException |
| 73 | + * @expectedExceptionMessage unserialize(): Error at offset 0 of 3 bytes |
| 74 | + */ |
| 75 | +publicfunctiontestNativeUnserializeInvalid() |
| 76 | + { |
| 77 | +set_error_handler(function () {returnfalse; }); |
| 78 | +try { |
| 79 | + @$this->unserializeValue(':::'); |
| 80 | + }finally { |
| 81 | +restore_error_handler(); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | +/** |
| 86 | + * @requires extension igbinary |
| 87 | + * @expectedException \DomainException |
| 88 | + * @expectedExceptionMessage igbinary_unserialize_zval: unknown type '61', position 5 |
| 89 | + */ |
| 90 | +publicfunctiontestIgbinaryUnserializeInvalid() |
| 91 | + { |
| 92 | +set_error_handler(function () {returnfalse; }); |
| 93 | +try { |
| 94 | + @$this->unserializeValue(rawurldecode('%00%00%00%02abc')); |
| 95 | + }finally { |
| 96 | +restore_error_handler(); |
| 97 | + } |
| 98 | + } |
| 99 | +} |