Debian Codegraph @

tests/phpunit/unit/includes/objectcache/RedisBagOStuffTest.php

raw symbols SCIP
1 <?php
2
3 use Wikimedia\ObjectCache\RedisBagOStuff;
4 use Wikimedia\TestingAccessWrapper;
5
6 /**
7 * @covers \Wikimedia\ObjectCache\RedisBagOStuff
8 * @group BagOStuff
9 */
10 class RedisBagOStuffTest extends MediaWikiUnitTestCase {
11
12 /** @var RedisBagOStuff */
13 private $cache;
14
15 protected function setUp(): void {
16 parent::setUp();
17
18 $cache = $this->createMock( RedisBagOStuff::class );
19 $this->cache = TestingAccessWrapper::newFromObject( $cache );
20 }
21
22 /**
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 static 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 * @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 }