From 8e81621dcf88490066cbc20d61b14b8781e04b41 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 7 Apr 2017 16:30:33 -0700 Subject: [PATCH] objectcache: Complete code coverage for CachedBagOStuff Change-Id: I8a228d68701f1ad4d37f60de53d105c32898dc8b --- includes/libs/objectcache/CachedBagOStuff.php | 32 ++++++++++-------- .../libs/objectcache/CachedBagOStuffTest.php | 33 +++++++++++++++++++ 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/includes/libs/objectcache/CachedBagOStuff.php b/includes/libs/objectcache/CachedBagOStuff.php index 496a4e8614..c85a82ea01 100644 --- a/includes/libs/objectcache/CachedBagOStuff.php +++ b/includes/libs/objectcache/CachedBagOStuff.php @@ -81,6 +81,22 @@ class CachedBagOStuff extends HashBagOStuff { $this->backend->setDebug( $bool ); } + public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) { + parent::deleteObjectsExpiringBefore( $date, $progressCallback ); + return $this->backend->deleteObjectsExpiringBefore( $date, $progressCallback ); + } + + public function makeKey() { + return call_user_func_array( [ $this->backend, __FUNCTION__ ], func_get_args() ); + } + + public function makeGlobalKey() { + return call_user_func_array( [ $this->backend, __FUNCTION__ ], func_get_args() ); + } + + // These just call the backend (tested elsewhere) + // @codeCoverageIgnoreStart + public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) { return $this->backend->lock( $key, $timeout, $expiry, $rclass ); } @@ -89,29 +105,17 @@ class CachedBagOStuff extends HashBagOStuff { return $this->backend->unlock( $key ); } - public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) { - parent::deleteObjectsExpiringBefore( $date, $progressCallback ); - return $this->backend->deleteObjectsExpiringBefore( $date, $progressCallback ); - } - public function getLastError() { return $this->backend->getLastError(); } public function clearLastError() { - $this->backend->clearLastError(); + return $this->backend->clearLastError(); } public function modifySimpleRelayEvent( array $event ) { return $this->backend->modifySimpleRelayEvent( $event ); } - public function makeKey() { - return call_user_func_array( [ $this->backend, __FUNCTION__ ], func_get_args() ); - } - - public function makeGlobalKey() { - return call_user_func_array( [ $this->backend, __FUNCTION__ ], func_get_args() ); - } - + // @codeCoverageIgnoreEnd } diff --git a/tests/phpunit/includes/libs/objectcache/CachedBagOStuffTest.php b/tests/phpunit/includes/libs/objectcache/CachedBagOStuffTest.php index 7b9d6d5f5b..5fbbdec3c8 100644 --- a/tests/phpunit/includes/libs/objectcache/CachedBagOStuffTest.php +++ b/tests/phpunit/includes/libs/objectcache/CachedBagOStuffTest.php @@ -83,6 +83,39 @@ class CachedBagOStuffTest extends PHPUnit_Framework_TestCase { $this->assertEquals( true, $cache->get( 'bar' ) ); } + /** + * @covers CachedBagOStuff::setDebug + */ + public function testSetDebug() { + $backend = new HashBagOStuff(); + $cache = new CachedBagOStuff( $backend ); + // Access private property 'debugMode' + $backend = TestingAccessWrapper::newFromObject( $backend ); + $cache = TestingAccessWrapper::newFromObject( $cache ); + $this->assertFalse( $backend->debugMode ); + $this->assertFalse( $cache->debugMode ); + + $cache->setDebug( true ); + // Should have set both + $this->assertTrue( $backend->debugMode, 'sets backend' ); + $this->assertTrue( $cache->debugMode, 'sets self' ); + } + + /** + * @covers CachedBagOStuff::deleteObjectsExpiringBefore + */ + public function testExpire() { + $backend = $this->getMockBuilder( HashBagOStuff::class ) + ->setMethods( [ 'deleteObjectsExpiringBefore' ] ) + ->getMock(); + $backend->expects( $this->once() ) + ->method( 'deleteObjectsExpiringBefore' ) + ->willReturn( false ); + + $cache = new CachedBagOStuff( $backend ); + $cache->deleteObjectsExpiringBefore( '20110401000000' ); + } + /** * @covers CachedBagOStuff::makeKey */ -- 2.20.1