objectcache: Forward MultiWriteBagOStuff::makeKey to primary backend
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / objectcache / MultiWriteBagOStuffTest.php
index 6df74d6..775709f 100644 (file)
@@ -23,6 +23,10 @@ class MultiWriteBagOStuffTest extends MediaWikiTestCase {
                ] );
        }
 
+       /**
+        * @covers MultiWriteBagOStuff::set
+        * @covers MultiWriteBagOStuff::doWrite
+        */
        public function testSetImmediate() {
                $key = wfRandomString();
                $value = wfRandomString();
@@ -34,6 +38,9 @@ class MultiWriteBagOStuffTest extends MediaWikiTestCase {
                $this->assertEquals( $value, $this->cache2->get( $key ), 'Written to tier 2' );
        }
 
+       /**
+        * @covers MultiWriteBagOStuff
+        */
        public function testSyncMerge() {
                $key = wfRandomString();
                $value = wfRandomString();
@@ -69,6 +76,9 @@ class MultiWriteBagOStuffTest extends MediaWikiTestCase {
                $dbw->commit();
        }
 
+       /**
+        * @covers MultiWriteBagOStuff::set
+        */
        public function testSetDelayed() {
                $key = wfRandomString();
                $value = wfRandomString();
@@ -88,4 +98,39 @@ class MultiWriteBagOStuffTest extends MediaWikiTestCase {
                // Set in tier 2
                $this->assertEquals( $value, $this->cache2->get( $key ), 'Written to tier 2' );
        }
+
+       /**
+        * @covers MultiWriteBagOStuff::makeKey
+        */
+       public function testMakeKey() {
+               $cache1 = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'makeKey' ] )->getMock();
+               $cache1->expects( $this->once() )->method( 'makeKey' )
+                       ->willReturn( 'special' );
+
+               $cache2 = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'makeKey' ] )->getMock();
+               $cache2->expects( $this->never() )->method( 'makeKey' );
+
+               $cache = new MultiWriteBagOStuff( [ 'caches' => [ $cache1, $cache2 ] ] );
+               $this->assertSame( 'special', $cache->makeKey( 'a', 'b' ) );
+       }
+
+       /**
+        * @covers MultiWriteBagOStuff::makeGlobalKey
+        */
+       public function testMakeGlobalKey() {
+               $cache1 = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'makeGlobalKey' ] )->getMock();
+               $cache1->expects( $this->once() )->method( 'makeGlobalKey' )
+                       ->willReturn( 'special' );
+
+               $cache2 = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'makeGlobalKey' ] )->getMock();
+               $cache2->expects( $this->never() )->method( 'makeGlobalKey' );
+
+               $cache = new MultiWriteBagOStuff( [ 'caches' => [ $cache1, $cache2 ] ] );
+
+               $this->assertSame( 'special', $cache->makeGlobalKey( 'a', 'b' ) );
+       }
 }