Merge "Title: Refactor JS/CSS page handling to be more sane"
[lhc/web/wiklou.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
10 use MediaWikiCoversValidator;
11
12 /** @var RedisBagOStuff */
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
23 /**
24 * @covers RedisBagOStuff::unserialize
25 * @dataProvider unserializeProvider
26 */
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
62 /**
63 * @covers RedisBagOStuff::serialize
64 * @dataProvider serializeProvider
65 */
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 }