Merge "registration: Only allow one extension to set a specific config setting"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / objectcache / WANObjectCacheTest.php
index 137ef0c..e23f318 100644 (file)
@@ -2,6 +2,20 @@
 
 use Wikimedia\TestingAccessWrapper;
 
+/**
+ * @covers WANObjectCache::wrap
+ * @covers WANObjectCache::unwrap
+ * @covers WANObjectCache::worthRefreshExpiring
+ * @covers WANObjectCache::worthRefreshPopular
+ * @covers WANObjectCache::isValid
+ * @covers WANObjectCache::getWarmupKeyMisses
+ * @covers WANObjectCache::prefixCacheKeys
+ * @covers WANObjectCache::getProcessCache
+ * @covers WANObjectCache::getNonProcessCachedKeys
+ * @covers WANObjectCache::getRawKeysForWarmup
+ * @covers WANObjectCache::getInterimValue
+ * @covers WANObjectCache::setInterimValue
+ */
 class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
        /** @var WANObjectCache */
        private $cache;
@@ -145,8 +159,9 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals( 9, $hit, "Values evicted" );
 
                $key = reset( $keys );
-               // Get into cache
+               // Get into cache (default process cache group)
                $this->cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
+               $this->assertEquals( 10, $hit, "Value calculated" );
                $this->cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
                $this->assertEquals( 10, $hit, "Value cached" );
                $outerCallback = function () use ( &$callback, $key ) {
@@ -154,7 +169,8 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
 
                        return 43 + $v;
                };
-               $this->cache->getWithSetCallback( $key, 100, $outerCallback );
+               // Outer key misses and refuses inner key process cache value
+               $this->cache->getWithSetCallback( "$key-miss-outer", 100, $outerCallback );
                $this->assertEquals( 11, $hit, "Nested callback value process cache skipped" );
        }
 
@@ -270,9 +286,9 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
 
        /**
         * @dataProvider getMultiWithSetCallback_provider
-        * @covers WANObjectCache::getMultiWithSetCallback()
-        * @covers WANObjectCache::makeMultiKeys()
-        * @covers WANObjectCache::getMulti()
+        * @covers WANObjectCache::getMultiWithSetCallback
+        * @covers WANObjectCache::makeMultiKeys
+        * @covers WANObjectCache::getMulti
         * @param array $extOpts
         * @param bool $versioned
         */
@@ -882,7 +898,9 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
        }
 
        /**
-        * @covers WANObjectCache::delete()
+        * @covers WANObjectCache::delete
+        * @covers WANObjectCache::relayDelete
+        * @covers WANObjectCache::relayPurge
         */
        public function testDelete() {
                $key = wfRandomString();
@@ -988,9 +1006,11 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
        }
 
        /**
-        * @covers WANObjectCache::touchCheckKey()
-        * @covers WANObjectCache::resetCheckKey()
-        * @covers WANObjectCache::getCheckKeyTime()
+        * @covers WANObjectCache::touchCheckKey
+        * @covers WANObjectCache::resetCheckKey
+        * @covers WANObjectCache::getCheckKeyTime
+        * @covers WANObjectCache::makePurgeValue
+        * @covers WANObjectCache::parsePurgeValue
         */
        public function testTouchKeys() {
                $key = wfRandomString();
@@ -1233,6 +1253,40 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
                ];
        }
 
+       /**
+        * @covers WANObjectCache::__construct
+        * @covers WANObjectCache::newEmpty
+        */
+       public function testNewEmpty() {
+               $this->assertInstanceOf(
+                       WANObjectCache::class,
+                       WANObjectCache::newEmpty()
+               );
+       }
+
+       /**
+        * @covers WANObjectCache::setLogger
+        */
+       public function testSetLogger() {
+               $this->assertSame( null, $this->cache->setLogger( new Psr\Log\NullLogger ) );
+       }
+
+       /**
+        * @covers WANObjectCache::getQoS
+        */
+       public function testGetQoS() {
+               $backend = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'getQoS' ] )->getMock();
+               $backend->expects( $this->once() )->method( 'getQoS' )
+                       ->willReturn( BagOStuff::QOS_UNKNOWN );
+               $wanCache = new WANObjectCache( [ 'cache' => $backend ] );
+
+               $this->assertSame(
+                       $wanCache::QOS_UNKNOWN,
+                       $wanCache->getQoS( $wanCache::ATTR_EMULATION )
+               );
+       }
+
        /**
         * @covers WANObjectCache::makeKey
         */