Follow-up cdc93a62bf: add serialize/unserialize tests for RedisBagOStuff
Bug: T134923 Change-Id: I0a7bec40c3fbf301720a248fbe21d46f5e64154c
This commit is contained in:
parent
4e691f2c5f
commit
c4e698dc27
1 changed files with 101 additions and 0 deletions
101
tests/phpunit/includes/objectcache/RedisBagOStuffTest.php
Normal file
101
tests/phpunit/includes/objectcache/RedisBagOStuffTest.php
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
/**
|
||||
* @group BagOStuff
|
||||
*/
|
||||
class RedisBagOStuffTest extends MediaWikiTestCase {
|
||||
/** @var RedisBagOStuff */
|
||||
private $cache;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->cache = TestingAccessWrapper::newFromObject( new RedisBagOStuff( [ 'servers' => [] ] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue