Follow-up cdc93a62bf: add serialize/unserialize tests for RedisBagOStuff
[lhc/web/wiklou.git] / tests / phpunit / includes / objectcache / RedisBagOStuffTest.php
1 <?php
2 /**
3 * @group BagOStuff
4 */
5 class RedisBagOStuffTest extends MediaWikiTestCase {
6 /** @var RedisBagOStuff */
7 private $cache;
8
9 protected function setUp() {
10 parent::setUp();
11 $this->cache = TestingAccessWrapper::newFromObject( new RedisBagOStuff( [ 'servers' => [] ] ) );
12 }
13
14 /**
15 * @covers RedisBagOStuff::unserialize
16 * @dataProvider unserializeProvider
17 */
18 public function testUnserialize( $expected, $input, $message ) {
19 $actual = $this->cache->unserialize( $input );
20 $this->assertSame( $expected, $actual, $message );
21 }
22
23 public function unserializeProvider() {
24 return [
25 [
26 -1,
27 '-1',
28 'String representation of \'-1\'',
29 ],
30 [
31 0,
32 '0',
33 'String representation of \'0\'',
34 ],
35 [
36 1,
37 '1',
38 'String representation of \'1\'',
39 ],
40 [
41 -1.0,
42 'd:-1;',
43 'Serialized negative double',
44 ],
45 [
46 'foo',
47 's:3:"foo";',
48 'Serialized string',
49 ]
50 ];
51 }
52
53 /**
54 * @covers RedisBagOStuff::serialize
55 * @dataProvider serializeProvider
56 */
57 public function testSerialize( $expected, $input, $message ) {
58 $actual = $this->cache->serialize( $input );
59 $this->assertSame( $expected, $actual, $message );
60 }
61
62 public function serializeProvider() {
63 return [
64 [
65 -1,
66 -1,
67 '-1 as integer',
68 ],
69 [
70 0,
71 0,
72 '0 as integer',
73 ],
74 [
75 1,
76 1,
77 '1 as integer',
78 ],
79 [
80 'd:-1;',
81 -1.0,
82 'Negative double',
83 ],
84 [
85 's:3:"2.1";',
86 '2.1',
87 'Decimal string',
88 ],
89 [
90 's:1:"1";',
91 '1',
92 'String representation of 1',
93 ],
94 [
95 's:3:"foo";',
96 'foo',
97 'String',
98 ],
99 ];
100 }
101 }