objectcache: Complete code coverage for CachedBagOStuff
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 7 Apr 2017 23:30:33 +0000 (16:30 -0700)
committerKrinkle <krinklemail@gmail.com>
Fri, 7 Apr 2017 23:31:41 +0000 (23:31 +0000)
Change-Id: I8a228d68701f1ad4d37f60de53d105c32898dc8b

includes/libs/objectcache/CachedBagOStuff.php
tests/phpunit/includes/libs/objectcache/CachedBagOStuffTest.php

index 496a4e8..c85a82e 100644 (file)
@@ -81,6 +81,22 @@ class CachedBagOStuff extends HashBagOStuff {
                $this->backend->setDebug( $bool );
        }
 
+       public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) {
+               parent::deleteObjectsExpiringBefore( $date, $progressCallback );
+               return $this->backend->deleteObjectsExpiringBefore( $date, $progressCallback );
+       }
+
+       public function makeKey() {
+               return call_user_func_array( [ $this->backend, __FUNCTION__ ], func_get_args() );
+       }
+
+       public function makeGlobalKey() {
+               return call_user_func_array( [ $this->backend, __FUNCTION__ ], func_get_args() );
+       }
+
+       // These just call the backend (tested elsewhere)
+       // @codeCoverageIgnoreStart
+
        public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
                return $this->backend->lock( $key, $timeout, $expiry, $rclass );
        }
@@ -89,29 +105,17 @@ class CachedBagOStuff extends HashBagOStuff {
                return $this->backend->unlock( $key );
        }
 
-       public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) {
-               parent::deleteObjectsExpiringBefore( $date, $progressCallback );
-               return $this->backend->deleteObjectsExpiringBefore( $date, $progressCallback );
-       }
-
        public function getLastError() {
                return $this->backend->getLastError();
        }
 
        public function clearLastError() {
-               $this->backend->clearLastError();
+               return $this->backend->clearLastError();
        }
 
        public function modifySimpleRelayEvent( array $event ) {
                return $this->backend->modifySimpleRelayEvent( $event );
        }
 
-       public function makeKey() {
-               return call_user_func_array( [ $this->backend, __FUNCTION__ ], func_get_args() );
-       }
-
-       public function makeGlobalKey() {
-               return call_user_func_array( [ $this->backend, __FUNCTION__ ], func_get_args() );
-       }
-
+       // @codeCoverageIgnoreEnd
 }
index 7b9d6d5..5fbbdec 100644 (file)
@@ -83,6 +83,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
         */