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