objectcache: Fix CachedBagOStuff to use backend makeKey()
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / objectcache / CachedBagOStuffTest.php
index 7fe8055..7b9d6d5 100644 (file)
@@ -5,6 +5,10 @@
  */
 class CachedBagOStuffTest extends PHPUnit_Framework_TestCase {
 
+       /**
+        * @covers CachedBagOStuff::__construct
+        * @covers CachedBagOStuff::doGet
+        */
        public function testGetFromBackend() {
                $backend = new HashBagOStuff;
                $cache = new CachedBagOStuff( $backend );
@@ -16,6 +20,10 @@ class CachedBagOStuffTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals( 'bar', $cache->get( 'foo' ), 'cached' );
        }
 
+       /**
+        * @covers CachedBagOStuff::set
+        * @covers CachedBagOStuff::delete
+        */
        public function testSetAndDelete() {
                $backend = new HashBagOStuff;
                $cache = new CachedBagOStuff( $backend );
@@ -30,6 +38,10 @@ class CachedBagOStuffTest extends PHPUnit_Framework_TestCase {
                }
        }
 
+       /**
+        * @covers CachedBagOStuff::set
+        * @covers CachedBagOStuff::delete
+        */
        public function testWriteCacheOnly() {
                $backend = new HashBagOStuff;
                $cache = new CachedBagOStuff( $backend );
@@ -50,6 +62,9 @@ class CachedBagOStuffTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals( 'old', $cache->get( 'foo' ) ); // Reloaded from backend
        }
 
+       /**
+        * @covers CachedBagOStuff::doGet
+        */
        public function testCacheBackendMisses() {
                $backend = new HashBagOStuff;
                $cache = new CachedBagOStuff( $backend );
@@ -67,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' ) );
+       }
 }