2016-05-12 22:01:03 +00:00
|
|
|
<?php
|
2017-04-19 19:37:35 +00:00
|
|
|
|
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
2016-05-12 22:01:03 +00:00
|
|
|
/**
|
2023-02-21 16:44:38 +00:00
|
|
|
* @covers RedisBagOStuff
|
2016-05-12 22:01:03 +00:00
|
|
|
* @group BagOStuff
|
|
|
|
|
*/
|
2019-07-07 23:28:25 +00:00
|
|
|
class RedisBagOStuffTest extends MediaWikiUnitTestCase {
|
2017-12-29 23:22:37 +00:00
|
|
|
|
2016-05-12 22:01:03 +00:00
|
|
|
/** @var RedisBagOStuff */
|
|
|
|
|
private $cache;
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2016-05-12 22:01:03 +00:00
|
|
|
parent::setUp();
|
2019-07-20 16:49:06 +00:00
|
|
|
|
2022-07-14 12:42:07 +00:00
|
|
|
$cache = $this->createMock( RedisBagOStuff::class );
|
2016-07-25 15:53:03 +00:00
|
|
|
$this->cache = TestingAccessWrapper::newFromObject( $cache );
|
2016-05-12 22:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider unserializeProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testUnserialize( $expected, $input, $message ) {
|
|
|
|
|
$actual = $this->cache->unserialize( $input );
|
|
|
|
|
$this->assertSame( $expected, $actual, $message );
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 22:32:30 +00:00
|
|
|
public static function unserializeProvider() {
|
2016-05-12 22:01:03 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
-1,
|
|
|
|
|
'-1',
|
|
|
|
|
'String representation of \'-1\'',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
0,
|
|
|
|
|
'0',
|
|
|
|
|
'String representation of \'0\'',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
1,
|
|
|
|
|
'1',
|
|
|
|
|
'String representation of \'1\'',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
-1.0,
|
|
|
|
|
'd:-1;',
|
|
|
|
|
'Serialized negative double',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'foo',
|
|
|
|
|
's:3:"foo";',
|
|
|
|
|
'Serialized string',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider serializeProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testSerialize( $expected, $input, $message ) {
|
|
|
|
|
$actual = $this->cache->serialize( $input );
|
|
|
|
|
$this->assertSame( $expected, $actual, $message );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function serializeProvider() {
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
'-1 as integer',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
'0 as integer',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
'1 as integer',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'd:-1;',
|
|
|
|
|
-1.0,
|
|
|
|
|
'Negative double',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
's:3:"2.1";',
|
|
|
|
|
'2.1',
|
|
|
|
|
'Decimal string',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
's:1:"1";',
|
|
|
|
|
'1',
|
|
|
|
|
'String representation of 1',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
's:3:"foo";',
|
|
|
|
|
'foo',
|
|
|
|
|
'String',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|