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