objectcache: Fix CachedBagOStuff to use backend makeKey()
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 7 Apr 2017 23:11:40 +0000 (16:11 -0700)
committerKrinkle <krinklemail@gmail.com>
Fri, 7 Apr 2017 23:31:25 +0000 (23:31 +0000)
Follows-up 25dbd91513f1e5.

Change-Id: Ib727c57cb27f05c0462bfdfee89a185ef6603ddd

includes/libs/objectcache/CachedBagOStuff.php
tests/phpunit/includes/libs/objectcache/CachedBagOStuffTest.php

index 74bf4b5..496a4e8 100644 (file)
@@ -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() );
+       }
+
 }
index a01cc6b..7b9d6d5 100644 (file)
@@ -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' ) );
+       }
 }