From a116bc58b535e7eb38dd0c73e8c4285813754ac3 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 7 Apr 2017 16:11:40 -0700 Subject: [PATCH] objectcache: Fix CachedBagOStuff to use backend makeKey() Follows-up 25dbd91513f1e5. Change-Id: Ib727c57cb27f05c0462bfdfee89a185ef6603ddd --- includes/libs/objectcache/CachedBagOStuff.php | 8 +++++ .../libs/objectcache/CachedBagOStuffTest.php | 36 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/includes/libs/objectcache/CachedBagOStuff.php b/includes/libs/objectcache/CachedBagOStuff.php index 74bf4b515f..496a4e8614 100644 --- a/includes/libs/objectcache/CachedBagOStuff.php +++ b/includes/libs/objectcache/CachedBagOStuff.php @@ -106,4 +106,12 @@ class CachedBagOStuff extends HashBagOStuff { 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() ); + } + } diff --git a/tests/phpunit/includes/libs/objectcache/CachedBagOStuffTest.php b/tests/phpunit/includes/libs/objectcache/CachedBagOStuffTest.php index a01cc6b7b8..7b9d6d5f5b 100644 --- a/tests/phpunit/includes/libs/objectcache/CachedBagOStuffTest.php +++ b/tests/phpunit/includes/libs/objectcache/CachedBagOStuffTest.php @@ -82,4 +82,40 @@ class CachedBagOStuffTest extends PHPUnit_Framework_TestCase { $backend->set( 'bar', true ); $this->assertEquals( true, $cache->get( 'bar' ) ); } + + /** + * @covers CachedBagOStuff::makeKey + */ + public function testMakeKey() { + $backend = $this->getMockBuilder( HashBagOStuff::class ) + ->setMethods( [ 'makeKey' ] ) + ->getMock(); + $backend->method( 'makeKey' ) + ->willReturn( 'special/logic' ); + + // CachedBagOStuff wraps any backend with a process cache + // using HashBagOStuff. Hash has no special key limitations, + // but backends often do. Make sure it uses the backend's + // makeKey() logic, not the one inherited from HashBagOStuff + $cache = new CachedBagOStuff( $backend ); + + $this->assertEquals( 'special/logic', $backend->makeKey( 'special', 'logic' ) ); + $this->assertEquals( 'special/logic', $cache->makeKey( 'special', 'logic' ) ); + } + + /** + * @covers CachedBagOStuff::makeGlobalKey + */ + public function testMakeGlobalKey() { + $backend = $this->getMockBuilder( HashBagOStuff::class ) + ->setMethods( [ 'makeGlobalKey' ] ) + ->getMock(); + $backend->method( 'makeGlobalKey' ) + ->willReturn( 'special/logic' ); + + $cache = new CachedBagOStuff( $backend ); + + $this->assertEquals( 'special/logic', $backend->makeGlobalKey( 'special', 'logic' ) ); + $this->assertEquals( 'special/logic', $cache->makeGlobalKey( 'special', 'logic' ) ); + } } -- 2.20.1