From: Timo Tijhof Date: Mon, 25 Sep 2017 23:21:40 +0000 (+0100) Subject: objectcache: Improve WANObjectCache test coverage X-Git-Tag: 1.31.0-rc.0~1933^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=6c8f3b9683b3647e7d9b090d964f261a3f347cd4 objectcache: Improve WANObjectCache test coverage class WANObjectCache (methods: 40% -> 67%, lines: 65% -> 88%) * Allow indirect coverage of protected/private utility methods from existing tests. * Add basic test for setLogger(). * Add basic test for newEmpty(). * Add basic test for getQoS(). Change-Id: Ifb79ed2ff1febbd2f5477b8ed6319992ce88eb29 --- diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index 137ef0c49a..0b2df619e3 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -2,6 +2,18 @@ use Wikimedia\TestingAccessWrapper; +/** + * @covers WANObjectCache::wrap + * @covers WANObjectCache::unwrap + * @covers WANObjectCache::worthRefreshExpiring + * @covers WANObjectCache::worthRefreshPopular + * @covers WANObjectCache::isValid + * @covers WANObjectCache::getWarmupKeyMisses + * @covers WANObjectCache::prefixCacheKeys + * @covers WANObjectCache::getProcessCache + * @covers WANObjectCache::getNonProcessCachedKeys + * @covers WANObjectCache::getRawKeysForWarmup + */ class WANObjectCacheTest extends PHPUnit_Framework_TestCase { /** @var WANObjectCache */ private $cache; @@ -270,9 +282,9 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase { /** * @dataProvider getMultiWithSetCallback_provider - * @covers WANObjectCache::getMultiWithSetCallback() - * @covers WANObjectCache::makeMultiKeys() - * @covers WANObjectCache::getMulti() + * @covers WANObjectCache::getMultiWithSetCallback + * @covers WANObjectCache::makeMultiKeys + * @covers WANObjectCache::getMulti * @param array $extOpts * @param bool $versioned */ @@ -882,7 +894,9 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase { } /** - * @covers WANObjectCache::delete() + * @covers WANObjectCache::delete + * @covers WANObjectCache::relayDelete + * @covers WANObjectCache::relayPurge */ public function testDelete() { $key = wfRandomString(); @@ -988,9 +1002,11 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase { } /** - * @covers WANObjectCache::touchCheckKey() - * @covers WANObjectCache::resetCheckKey() - * @covers WANObjectCache::getCheckKeyTime() + * @covers WANObjectCache::touchCheckKey + * @covers WANObjectCache::resetCheckKey + * @covers WANObjectCache::getCheckKeyTime + * @covers WANObjectCache::makePurgeValue + * @covers WANObjectCache::parsePurgeValue */ public function testTouchKeys() { $key = wfRandomString(); @@ -1233,6 +1249,40 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase { ]; } + /** + * @covers WANObjectCache::__construct + * @covers WANObjectCache::newEmpty + */ + public function testNewEmpty() { + $this->assertInstanceOf( + WANObjectCache::class, + WANObjectCache::newEmpty() + ); + } + + /** + * @covers WANObjectCache::setLogger + */ + public function testSetLogger() { + $this->assertSame( null, $this->cache->setLogger( new Psr\Log\NullLogger ) ); + } + + /** + * @covers WANObjectCache::getQoS + */ + public function testGetQoS() { + $backend = $this->getMockBuilder( HashBagOStuff::class ) + ->setMethods( [ 'getQoS' ] )->getMock(); + $backend->expects( $this->once() )->method( 'getQoS' ) + ->willReturn( BagOStuff::QOS_UNKNOWN ); + $wanCache = new WANObjectCache( [ 'cache' => $backend ] ); + + $this->assertSame( + $wanCache::QOS_UNKNOWN, + $wanCache->getQoS( $wanCache::ATTR_EMULATION ) + ); + } + /** * @covers WANObjectCache::makeKey */