wiki.techinc.nl/tests/phpunit/unit/includes/objectcache/RedisBagOStuffTest.php
Thiemo Kreuz 61ae7504df Replace trivial usa of mock builder with createMock() shortcut
createMock() does the same, but is much easier to read.

A small difference is that some of the replacements made in this
patch didn't use disableOriginalConstructor() before. In case this
was relevant we should see the respective test fail. If not we can
save some CPU cycles and skip these constructors.

Change-Id: Ib98fb06e0fe753b7a53cb087a47e1159515a8ad5
2022-07-15 16:43:48 +00:00

107 lines
1.7 KiB
PHP

<?php
use Wikimedia\TestingAccessWrapper;
/**
* @group BagOStuff
*/
class RedisBagOStuffTest extends MediaWikiUnitTestCase {
/** @var RedisBagOStuff */
private $cache;
protected function setUp(): void {
parent::setUp();
$cache = $this->createMock( RedisBagOStuff::class );
$this->cache = TestingAccessWrapper::newFromObject( $cache );
}
/**
* @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',
],
];
}
}