objectcache: Use variadic signature for makeKey()
[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
16 if ( defined( 'HHVM_VERSION' ) ) {
17 $this->markTestSkipped( 'HHVM Reflection buggy' );
18 }
19
20 $cache = $this->getMockBuilder( RedisBagOStuff::class )
21 ->disableOriginalConstructor()
22 ->getMock();
23 $this->cache = TestingAccessWrapper::newFromObject( $cache );
24 }
25
26 /**
27 * @covers RedisBagOStuff::unserialize
28 * @dataProvider unserializeProvider
29 */
30 public function testUnserialize( $expected, $input, $message ) {
31 $actual = $this->cache->unserialize( $input );
32 $this->assertSame( $expected, $actual, $message );
33 }
34
35 public function unserializeProvider() {
36 return [
37 [
38 -1,
39 '-1',
40 'String representation of \'-1\'',
41 ],
42 [
43 0,
44 '0',
45 'String representation of \'0\'',
46 ],
47 [
48 1,
49 '1',
50 'String representation of \'1\'',
51 ],
52 [
53 -1.0,
54 'd:-1;',
55 'Serialized negative double',
56 ],
57 [
58 'foo',
59 's:3:"foo";',
60 'Serialized string',
61 ]
62 ];
63 }
64
65 /**
66 * @covers RedisBagOStuff::serialize
67 * @dataProvider serializeProvider
68 */
69 public function testSerialize( $expected, $input, $message ) {
70 $actual = $this->cache->serialize( $input );
71 $this->assertSame( $expected, $actual, $message );
72 }
73
74 public function serializeProvider() {
75 return [
76 [
77 -1,
78 -1,
79 '-1 as integer',
80 ],
81 [
82 0,
83 0,
84 '0 as integer',
85 ],
86 [
87 1,
88 1,
89 '1 as integer',
90 ],
91 [
92 'd:-1;',
93 -1.0,
94 'Negative double',
95 ],
96 [
97 's:3:"2.1";',
98 '2.1',
99 'Decimal string',
100 ],
101 [
102 's:1:"1";',
103 '1',
104 'String representation of 1',
105 ],
106 [
107 's:3:"foo";',
108 'foo',
109 'String',
110 ],
111 ];
112 }
113 }