MediaWiki REL1_31
RedisBagOStuffTest.php
Go to the documentation of this file.
1<?php
2
3use Wikimedia\TestingAccessWrapper;
4
8class RedisBagOStuffTest extends PHPUnit\Framework\TestCase {
9
10 use MediaWikiCoversValidator;
11
13 private $cache;
14
15 protected function setUp() {
16 parent::setUp();
17 $cache = $this->getMockBuilder( RedisBagOStuff::class )
18 ->disableOriginalConstructor()
19 ->getMock();
20 $this->cache = TestingAccessWrapper::newFromObject( $cache );
21 }
22
27 public function testUnserialize( $expected, $input, $message ) {
28 $actual = $this->cache->unserialize( $input );
29 $this->assertSame( $expected, $actual, $message );
30 }
31
32 public function unserializeProvider() {
33 return [
34 [
35 -1,
36 '-1',
37 'String representation of \'-1\'',
38 ],
39 [
40 0,
41 '0',
42 'String representation of \'0\'',
43 ],
44 [
45 1,
46 '1',
47 'String representation of \'1\'',
48 ],
49 [
50 -1.0,
51 'd:-1;',
52 'Serialized negative double',
53 ],
54 [
55 'foo',
56 's:3:"foo";',
57 'Serialized string',
58 ]
59 ];
60 }
61
66 public function testSerialize( $expected, $input, $message ) {
67 $actual = $this->cache->serialize( $input );
68 $this->assertSame( $expected, $actual, $message );
69 }
70
71 public function serializeProvider() {
72 return [
73 [
74 -1,
75 -1,
76 '-1 as integer',
77 ],
78 [
79 0,
80 0,
81 '0 as integer',
82 ],
83 [
84 1,
85 1,
86 '1 as integer',
87 ],
88 [
89 'd:-1;',
90 -1.0,
91 'Negative double',
92 ],
93 [
94 's:3:"2.1";',
95 '2.1',
96 'Decimal string',
97 ],
98 [
99 's:1:"1";',
100 '1',
101 'String representation of 1',
102 ],
103 [
104 's:3:"foo";',
105 'foo',
106 'String',
107 ],
108 ];
109 }
110}
testSerialize( $expected, $input, $message)
RedisBagOStuff::serialize serializeProvider.
testUnserialize( $expected, $input, $message)
RedisBagOStuff::unserialize unserializeProvider.
Redis-based caching module for redis server >= 2.6.12 and phpredis >= 2.2.4.
you have access to all of the normal MediaWiki so you can get a DB use the cache
if(is_array($mode)) switch( $mode) $input