Use MediaWikiCoversValidator for tests that don't use MediaWikiTestCase
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / objectcache / CachedBagOStuffTest.php
index 7b9d6d5..d71b16c 100644 (file)
@@ -1,10 +1,14 @@
 <?php
 
+use Wikimedia\TestingAccessWrapper;
+
 /**
  * @group BagOStuff
  */
 class CachedBagOStuffTest extends PHPUnit_Framework_TestCase {
 
+       use MediaWikiCoversValidator;
+
        /**
         * @covers CachedBagOStuff::__construct
         * @covers CachedBagOStuff::doGet
@@ -83,6 +87,39 @@ class CachedBagOStuffTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals( true, $cache->get( 'bar' ) );
        }
 
+       /**
+        * @covers CachedBagOStuff::setDebug
+        */
+       public function testSetDebug() {
+               $backend = new HashBagOStuff();
+               $cache = new CachedBagOStuff( $backend );
+               // Access private property 'debugMode'
+               $backend = TestingAccessWrapper::newFromObject( $backend );
+               $cache = TestingAccessWrapper::newFromObject( $cache );
+               $this->assertFalse( $backend->debugMode );
+               $this->assertFalse( $cache->debugMode );
+
+               $cache->setDebug( true );
+               // Should have set both
+               $this->assertTrue( $backend->debugMode, 'sets backend' );
+               $this->assertTrue( $cache->debugMode, 'sets self' );
+       }
+
+       /**
+        * @covers CachedBagOStuff::deleteObjectsExpiringBefore
+        */
+       public function testExpire() {
+               $backend = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'deleteObjectsExpiringBefore' ] )
+                       ->getMock();
+               $backend->expects( $this->once() )
+                       ->method( 'deleteObjectsExpiringBefore' )
+                       ->willReturn( false );
+
+               $cache = new CachedBagOStuff( $backend );
+               $cache->deleteObjectsExpiringBefore( '20110401000000' );
+       }
+
        /**
         * @covers CachedBagOStuff::makeKey
         */