Merge "Tell users that js/css subpages are public"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / objectcache / BagOStuffTest.php
index 96e200d..92fb954 100644 (file)
@@ -138,6 +138,20 @@ class BagOStuffTest extends MediaWikiTestCase {
                }
        }
 
+       /**
+        * @covers BagOStuff::changeTTL
+        */
+       public function testChangeTTL() {
+               $key = wfMemcKey( 'test' );
+               $value = 'meow';
+
+               $this->cache->add( $key, $value );
+               $this->assertTrue( $this->cache->changeTTL( $key, 5 ) );
+               $this->assertEquals( $this->cache->get( $key ), $value );
+               $this->cache->delete( $key );
+               $this->assertFalse( $this->cache->changeTTL( $key, 5 ) );
+       }
+
        /**
         * @covers BagOStuff::add
         */
@@ -252,4 +266,29 @@ class BagOStuffTest extends MediaWikiTestCase {
                $this->assertType( 'ScopedCallback', $value1, 'First reentrant call returned lock' );
                $this->assertType( 'ScopedCallback', $value1, 'Second reentrant call returned lock' );
        }
+
+       /**
+        * @covers BagOStuff::__construct
+        * @covers BagOStuff::trackDuplicateKeys
+        */
+       public function testReportDupes() {
+               $logger = $this->getMock( 'Psr\Log\NullLogger' );
+               $logger->expects( $this->once() )
+                       ->method( 'warning' )
+                       ->with( 'Duplicate get(): "{key}" fetched {count} times', [
+                               'key' => 'foo',
+                               'count' => 2,
+                       ] );
+
+               $cache = new HashBagOStuff( [
+                       'reportDupes' => true,
+                       'asyncHandler' => 'DeferredUpdates::addCallableUpdate',
+                       'logger' => $logger,
+               ] );
+               $cache->get( 'foo' );
+               $cache->get( 'bar' );
+               $cache->get( 'foo' );
+
+               DeferredUpdates::doUpdates();
+       }
 }