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
|
|
|
/**
|
|
|
|
|
* @group BagOStuff
|
|
|
|
|
*/
|
2018-02-17 12:29:13 +00:00
|
|
|
class RedisBagOStuffTest extends PHPUnit\Framework\TestCase {
|
2017-12-29 23:22:37 +00:00
|
|
|
|
|
|
|
|
use MediaWikiCoversValidator;
|
|
|
|
|
|
2016-05-12 22:01:03 +00:00
|
|
|
/** @var RedisBagOStuff */
|
|
|
|
|
private $cache;
|
|
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
2018-01-13 00:02:09 +00:00
|
|
|
$cache = $this->getMockBuilder( RedisBagOStuff::class )
|
2016-07-25 15:53:03 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$this->cache = TestingAccessWrapper::newFromObject( $cache );
|
2016-05-12 22:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers RedisBagOStuff::unserialize
|
|
|
|
|
* @dataProvider unserializeProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testUnserialize( $expected, $input, $message ) {
|
|
|
|
|
$actual = $this->cache->unserialize( $input );
|
|
|
|
|
$this->assertSame( $expected, $actual, $message );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function unserializeProvider() {
|
|
|
|
|
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',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers RedisBagOStuff::serialize
|
|
|
|
|
* @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',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|