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